fix: close sync/error pipe fds when fork() fails in _spawn() - #278
Draft
toddr-bot wants to merge 2 commits into
Draft
fix: close sync/error pipe fds when fork() fails in _spawn()#278toddr-bot wants to merge 2 commits into
toddr-bot wants to merge 2 commits into
Conversation
When fork() fails, _spawn() would croak without closing the sync pipe and coderef error pipe file descriptors it had just created. These fds leaked because the local reader variables were lost when the function exited, and _cleanup() has no knowledge of these temporary pipes. Move the _simulate_fork_failure logic into _spawn() (after pipe creation) so the existing test exercises the real cleanup path. Add a CODE ref variant that also covers the coderef_err pipe cleanup. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Declared near reap_nb() but never referenced anywhere. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Close file descriptors that leak when
fork()fails inside_spawn().Why
When
fork()fails after_spawn()has already created the sync pipe (andoptionally the coderef error pipe for CODE ref children), those file descriptors
leak. The local reader fd variables are lost when
_spawn()croaks, and_cleanup()has no knowledge of these temporary pipes.The existing
_simulate_fork_failuretest didn't catch this because it triggeredbefore
_spawn()was called — the pipes were never created in the first place.How
_spawn()on forkfailure, before re-throwing
_simulate_fork_failuresimulation into_spawn()(after pipecreation) so the existing fd-leak test (
_map_fdscomparison) actuallyexercises the real cleanup path
pipe cleanup
Testing
t/run.tpass (4 new)t/pty.tskips (IO::Pty < 1.25, pre-existing)🤖 Generated with Claude Code
Quality Report
Changes: 2 files changed, 37 insertions(+), 9 deletions(-)
Code scan: clean
Tests: failed (0 Failed, 37 tests)
Branch hygiene: clean
Generated by Kōan post-mission quality pipeline