Skip to content

fix: handle fork failure gracefully in daemon and forkm.t#64

Draft
toddr-bot wants to merge 1 commit into
mainfrom
koan.toddr.bot/handle-fork-failure
Draft

fix: handle fork failure gracefully in daemon and forkm.t#64
toddr-bot wants to merge 1 commit into
mainfrom
koan.toddr.bot/handle-fork-failure

Conversation

@toddr-bot
Copy link
Copy Markdown

@toddr-bot toddr-bot commented Apr 12, 2026

What

Handle fork() failures gracefully instead of crashing.

Why

CPAN testers v0.52 shows a FAIL on OpenBSD 7.7 (perl 5.40.3, threaded) — forkm.t dies with "Resource temporarily unavailable" when the smoker hits RLIMIT_NPROC. The server also dies on fork failure, which is wrong for a production daemon: temporary resource exhaustion shouldn't crash the process.

How

  • Daemon.pm ChildFunc(): Replace die with Error() log + return on fork failure. The parent closes the client socket and continues accepting.
  • forkm.t: Stop spawning on fork failure instead of dying. Dynamically adjust the test plan to match children actually created. skip_all if zero children could be spawned.

Testing

  • Full test suite passes locally (18 test files, 83+ subtests)
  • Fork failure path in forkm.t produces clean skip_all or reduced plan instead of exit code 35

🤖 Generated with Claude Code


Quality Report

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

Code scan: clean

Tests: passed (OK)

Branch hygiene: clean

Generated by Kōan post-mission quality pipeline

CPAN testers v0.52 shows a FAIL on OpenBSD 7.7 (perl 5.40.3 threaded)
where forkm.t dies with "Resource temporarily unavailable" due to
RLIMIT_NPROC on constrained smoker machines.

Two fixes:

1. Daemon.pm ChildFunc(): Replace die with Error() log + return when
   fork() fails.  A temporary resource exhaustion should not crash the
   entire daemon — the parent closes the client socket and continues
   accepting new connections.

2. forkm.t: Stop spawning on fork failure instead of dying.  Adjust
   the test plan to match the number of children actually created.
   Skip the entire test if zero children could be spawned.

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