Skip to content

Commit 458a35c

Browse files
committed
Surface silent failures in _subint_forkserver
Three places that previously swallowed exceptions silently now log via `log.exception()` so they surface in the runtime log when something weird happens — easier to track down sneaky failures in the fork-from-worker-thread / subint-bootstrap primitives. Deats, - `_close_inherited_fds()`: post-fork child's per-fd `os.close()` swallow now logs the fd that failed to close. The comment notes the expected failure modes (already-closed-via-listdir-race, otherwise-unclosable) — both still fine to ignore semantically, but worth flagging in the log. - `fork_from_worker_thread()` parent-side timeout branch: the `os.close(rfd)` + `os.close(wfd)` cleanup now logs each pipe-fd close failure separately before raising the `worker thread didn't return` RuntimeError. - `run_subint_in_worker_thread._drive()`: when `_interpreters.exec(interp_id, bootstrap)` raises a `BaseException`, log the full call signature (interp_id + bootstrap) along with the captured exception, before stashing into `err` for the outer caller. Behavior unchanged — only adds observability. (this commit msg was generated in some part by [`claude-code`][claude-code-gh]) [claude-code-gh]: https://github.com/anthropics/claude-code
1 parent 7cd47ef commit 458a35c

1 file changed

Lines changed: 22 additions & 5 deletions

File tree

tractor/spawn/_subint_forkserver.py

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -252,9 +252,13 @@ def _close_inherited_fds(
252252
os.close(fd)
253253
closed += 1
254254
except OSError:
255-
# fd was already closed (race with listdir) or
256-
# otherwise unclosable — either is fine.
257-
pass
255+
# fd was already closed (race with listdir) or otherwise
256+
# unclosable — either is fine.
257+
log.exception(
258+
f'Failed to close inherited fd in child ??\n'
259+
f'{fd!r}\n'
260+
)
261+
258262
return closed
259263

260264

@@ -401,11 +405,17 @@ def _worker() -> None:
401405
try:
402406
os.close(rfd)
403407
except OSError:
404-
pass
408+
log.exception(
409+
f'Failed to close PID-pipe read-fd in parent ??\n'
410+
f'{rfd!r}\n'
411+
)
405412
try:
406413
os.close(wfd)
407414
except OSError:
408-
pass
415+
log.exception(
416+
f'Failed to close PID-pipe write-fd in parent ??\n'
417+
f'{wfd!r}\n'
418+
)
409419
raise RuntimeError(
410420
f'subint-forkserver worker thread '
411421
f'{thread_name!r} did not return within '
@@ -475,6 +485,13 @@ def _drive() -> None:
475485
_interpreters.exec(interp_id, bootstrap)
476486
except BaseException as e:
477487
err = e
488+
log.exception(
489+
f'Failed to .exec() in subint ??\n'
490+
f'_interpreters.exec(\n'
491+
f' interp_id={interp_id!r},\n'
492+
f' bootstrap={bootstrap!r},\n'
493+
f') => {err!r}\n'
494+
)
478495

479496
worker: threading.Thread = threading.Thread(
480497
target=_drive,

0 commit comments

Comments
 (0)