You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 5e73e7f
Browse filesBrowse the repository at this point in the historyBrowse files
fix: run() must own its child from creation, not after logging
`LoggingSubprocess.run()` logged "Command started as pid" and "Output:", and
did the POSIX process-group lookup, *before* entering the `try` whose `finally`
reaps the child. Anything raising in that window escaped `run()` having never
waited on the child: a live process, no exit code recorded, and the runner
publishing a terminal state for it anyway.
The reachable trigger is a `logging.Filter` that raises. Filters propagate out
of `Logger.handle`, unlike handlers, whose exceptions are routed to
`handleError` -- and installing a filter is a supported use of this library;
`Session` installs its own. Reproduced before the fix: the child stayed alive
with `exit_code is None`, while a filter raising from inside the pump (already
covered by the `finally`) reaped correctly.
The ownership `try` now begins immediately after successful process creation, so
every exit path from that point goes through `_reap`. The body binds
`proc = self._process` once instead of re-reading the attribute, matching the
bind-once convention used by `notify()`/`terminate()`.
`_reap`'s own logging is now best-effort. It runs inside `run()`'s `finally`, so
anything escaping it replaces the exception already propagating and hides the
real cause. That containment was in place for the terminate and the wait but not
for the three `logger.error` calls between them -- and a raising logging stack is
exactly what routes execution into `_reap`, which makes those calls the likeliest
thing to fail there, not the least.
Reported by mwiebe on #333:
#333 (comment)
Two honest notes on the scope of the fix:
- Reordering `_reap` to terminate before logging was tried and dropped. With
best-effort logging in place the swallow already lets the terminate run, so the
ordering changed nothing an `Exception` could observe; it only guarded a
`BaseException` from the logging stack, which cannot reach the pool worker
thread `run()` executes on. Mutation testing proved it inert, so it is not
shipped rather than shipped behind a contrived test.
- When the process-group lookup is *itself* what fails, the boundary buys the
reap attempt and the handle release but not the kill: with no group recorded,
`_posix_signal_subprocess` declines to signal rather than target a possibly
recycled pid (the R5-9 convention). That is a pre-existing limitation of the
signalling path, not something this change introduces, and the test for that
path asserts only what actually happens. Recorded as a follow-up.
Tests: 6 added. Every one mutation-checked -- 5 mutants, 0 survivors: the
startup logging moved back outside the boundary, the process-group lookup moved
back outside it, and each of the three reap log sites bypassing best-effort. The
pre-existing 13 tests in the file pass unmodified. Full suite 884 passed;
ruff, black, and mypy clean on native and --platform win32.
Signed-off-by: David Leong <116610336+leongdl@users.noreply.github.com>
(cherry picked from commit acee655)
0 commit comments