fix: replace 11 bare except clauses with except Exception#444
fix: replace 11 bare except clauses with except Exception#444haosenwang1018 wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR replaces several bare except: clauses in billiard with except Exception: in an effort to avoid catching BaseException subclasses (e.g., KeyboardInterrupt, SystemExit).
Changes:
- Replace bare
except:withexcept Exception:across multiple process/IPC-related modules. - Narrow exception handling in resource/handle cleanup and background service loops.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
billiard/semaphore_tracker.py |
Narrows exception handlers in tracker startup and exception-reporting path. |
billiard/resource_sharer.py |
Narrows the server loop’s catch-all handler. |
billiard/process.py |
Narrows _bootstrap() outermost catch-all handler. |
billiard/popen_spawn_win32.py |
Narrows Windows handle cleanup catch-all handler during process spawn. |
billiard/managers.py |
Narrows exception handling during manager shutdown response. |
billiard/forkserver.py |
Narrows fd cleanup handlers in forkserver connection/spawn logic. |
billiard/connection.py |
Narrows overlapped I/O cleanup handlers on Windows pipe operations. |
billiard/compat.py |
Narrows sysconf failure handling in get_fdmax. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| except Exception: | ||
| ov.cancel() | ||
| raise |
There was a problem hiding this comment.
This except ensures ov.cancel() runs if the wait/write fails. With except Exception, KeyboardInterrupt/SystemExit during the wait will bypass cancellation, potentially leaving an overlapped I/O pending and leaking resources. Use except BaseException for the cancel-and-reraise pattern here.
There was a problem hiding this comment.
can you please cross check this suggestion?
| except Exception: | ||
| exitcode = 1 | ||
| if not util.error('Process %s', self.name, exc_info=True): |
There was a problem hiding this comment.
exitcode is only set inside the try/except blocks. With except Exception, a KeyboardInterrupt/SystemExit raised anywhere in the outer try will skip the handlers and hit finally, where exitcode is referenced, causing an UnboundLocalError and masking the real reason for exit. Either initialize exitcode before the try and/or handle BaseException to ensure exitcode is always defined.
| reduction.sendfds(client, allfds) | ||
| return parent_r, parent_w | ||
| except: | ||
| except Exception: |
There was a problem hiding this comment.
This block is closing parent_r/parent_w on failure, but except Exception won’t run for KeyboardInterrupt/SystemExit, which can leak both fds. Use except BaseException for cleanup-and-reraise here, or move the closes to a finally that runs for all exception types when returning doesn’t happen.
| except Exception: | |
| except BaseException: |
8c1802b to
96daa40
Compare
Nusnus
left a comment
There was a problem hiding this comment.
@copilot code review[agent] comments seems legit. Please review @haosenwang1018
96daa40 to
40f3aa3
Compare
|
Closing broad-scope change per backlog policy; can resubmit in smaller chunks. |
Replace bare except clauses with except Exception.