Skip to content

fix: handle fork failure gracefully in preforking mode#69

Draft
toddr-bot wants to merge 1 commit into
mainfrom
koan.toddr.bot/fix-prefork-failure
Draft

fix: handle fork failure gracefully in preforking mode#69
toddr-bot wants to merge 1 commit into
mainfrom
koan.toddr.bot/fix-prefork-failure

Conversation

@toddr-bot
Copy link
Copy Markdown

@toddr-bot toddr-bot commented May 20, 2026

What

Handle fork() failure in the preforking loop of Bind() without crashing the server.

Why

When --childs=N is used and fork() fails mid-loop (e.g., RLIMIT_NPROC), the
previous die "Cannot fork: $!" crashed the parent process, orphaning any
children that were already forked. This is the preforking counterpart to #64
which fixed the same class of bug in ChildFunc().

How

  • Replace die with Error() + last — logs the failure and stops forking
  • If zero children were created, call Fatal() (server can't operate)
  • If partial children were created, log a warning and continue with the reduced pool
  • Parent coordinator proceeds normally with whatever children were forked

Testing

  • New t/prefork_failure.t — uses CORE::GLOBAL::fork override to simulate
    fork failure without creating real child processes
  • Full test suite passes (19 files)

🤖 Generated with Claude Code


Quality Report

Changes: 2 files changed, 157 insertions(+), 2 deletions(-)

Code scan: clean

Tests: passed (OK)

Branch hygiene: clean

Generated by Kōan post-mission quality pipeline

Replace die with Error + last when fork() fails during the preforking
loop in Bind().  Previously a fork failure mid-loop would crash the
parent and orphan already-forked children.  Now the server logs the
error, stops forking, and either continues with partial children or
calls Fatal if zero children were created.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant