Skip to content

fix: preserve child termination signals in the npm wrapper - #85

Merged
alexshapalov merged 1 commit into
pgrundev:mainfrom
DivyamTalwar:fix/preserve-wrapper-signal-exits
Sep 27, 2026
Merged

alexshapalov merged 1 commit into
pgrundev:mainfrom
DivyamTalwar:fix/preserve-wrapper-signal-exits

Conversation

@DivyamTalwar

Copy link
Copy Markdown
Contributor

What and why

Closes #84.

Remove the registered forwarding handlers immediately before reproducing a child's terminating signal on the wrapper process. Otherwise the wrapper catches its own final signal and can report successful exit zero.

Forwarding remains active while the binary runs, and graceful numeric exits remain intact. The tests use real child processes and the actual npm layout, bounded readiness/exit waits and cleanup of owned processes. They retain coverage for a child that handles TERM and exits 143.

Verification

Verified commit: 32dd69c0b3bdb3974c7a857bdeaefb2ea3a3cc77.

  • RED on upstream 282ffe8fdd7acdd7b6e1dbd8cf04c155401d3a92: child self-SIGTERM yields wrapper exit 0 instead of SIGTERM.
  • node --test npm/test/wrapper.test.mjs: all 11 tests pass on macOS/arm64 (Node v25.2.1).
  • Ten repeated complete wrapper-suite runs pass, including SIGTERM, SIGINT, SIGHUP and graceful numeric exit 143.
  • bash scripts/gate.sh: passes committed HEAD, including pinned lint, unit tests and all six Go release-target builds.
  • go test -race ./...: passes.
  • bash npm/test/pack-smoke.sh npm bun: passes actual local tarball installations with lifecycle scripts disabled and executes the real binary via Node and Bun runtimes.
  • git diff --check: clean.

Scope and risk

The signal-process fixtures are POSIX-specific; this does not claim Windows runtime signal validation. Numeric exit codes, arguments and missing-package diagnostics remain unchanged. No dependencies, collector SQL, database migrations or JSON changes. Revert the commit to restore the prior handler lifecycle.

Checklist

  • scripts/gate.sh passes on committed HEAD; full race suite passes.
  • Read-only, privacy and deterministic-finding invariants preserved.
  • No new finding or model.Context field; catalog/model schema unchanged.

The wrapper intercepted its own final re-raised signal with the forwarding
listener, allowing a signaled child to become a successful wrapper exit.

Track forwarding handlers and remove them only before the final self-signal.
Keep forwarding while the binary runs and preserve numeric graceful exits.
Replace the unbounded fixed-delay signal test with ready-file handshakes,
bounded waits and cleanup of both owned processes.

Verification: the real wrapper returns zero after self-SIGTERM on base
282ffe8, while the corrected suite passes all 11 tests. Controls cover
SIGINT, SIGTERM, SIGHUP, graceful exit 143, normal exit 0, nonzero exit 2,
spawn failure 3, missing package 64 and argument forwarding.
@alexshapalov
alexshapalov merged commit a38df60 into pgrundev:main Sep 27, 2026
19 checks passed
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.

The npm wrapper can turn a signaled child into exit status zero

2 participants