Repository navigation
fix(node:child_process): cancel pending stdin writes on destroy - #170
Conversation
Reapply #165 with the pending-only native guard from oven-sh#45233. Preserve graceful close when no write is pending and keep the fork short-write flush path.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ba8961295d
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| return; | ||
| } | ||
| this.fd = null; | ||
| cb(err); |
There was a problem hiding this comment.
Finish cancellation before completing stream destruction
When destroy() interrupts a backpressured child-stdin write, the native hook only schedules rejection of the pending write, but this immediately completes _destroy; consequently the stream can emit close before the write callback receives ECANCELED. Node 24.15 delivers the canceled write callback before close, so close listeners can otherwise tear down state and then unexpectedly receive a late callback. Defer this callback until the canceled write has settled.
Useful? React with 👍 / 👎.
| }), | ||
| ).toBe(false); | ||
| stdin.destroy(destroyed); | ||
| watchdog = setTimeout(() => written.reject(new Error("pending write was not canceled")), 3000); |
There was a problem hiding this comment.
Remove the hard-coded watchdog timeout
On slow debug/ASAN or heavily contended CI workers, the cancellation can still be correct but take longer than this arbitrary three-second deadline, producing a false failure before Bun's test runner timeout. Await the write callback directly and let the runner diagnose a hang instead of adding a shorter timer.
AGENTS.md reference: test/AGENTS.md:L118-L120
Useful? React with 👍 / 👎.
What does this PR do?
Reapply #165 after its temporary revert in #169, with the pending-only cancellation guard from oven-sh/bun#45233.
A pending child-stdin write is canceled before the child exits. The write callback receives Node's
write ECANCELEDerror, while the stream preserves the caller's original destroy error. The native hook now returns false when no write is pending, so the adapter retains its previous graceful close path. The cancellation functions match the upstream proposal; the surrounding fork write/flush logic remains unchanged, including flushing acknowledged short writes.How did you verify your code works?
Windows dry run 38560335414 builds this branch with an empty tag and
publish=false. Both Windows architectures pass the unchanged shared 31-file compatibility selection, includingchild-process-stdio.test.jsand the two #165 pending-destroy regressions inchild_process.test.ts. Both smoke tests also pass. The selected file lists and child-process test sources are identical to the failing candidate.child.stdin.unref releases the stdin writer keep-alivechild-process-stdio.test.jschild_process.test.tsThe earlier 34fc20de prerelease, run 38515471328, also passed both Windows compatibility jobs. The guarded candidate's stdio file still takes about 30 seconds on Windows; this proof removes the assertion failure and does not claim faster unref exit behavior.
Node 24.21.0 passes both pending-write cases (with and without a destroy error): one ECANCELED callback with the platform errno and write syscall, original stream error preserved, and completion while the child remains alive.
Linux/macOS build-and-test run 38564656907 passed. Both platform reports contain only passing file results. Format, JavaScript lint, source lint, Clippy, Miri, mordant, and the Rust library tests passed. The only red check is the known
claude-find-issuesconfiguration failure: no Anthropic credential is configured for that workflow. Independent Codex and Claude P2 reviews are scoped-clean.Upstream oven-sh#45233 is open at d413fdd, but its Buildkite run is blocked before jobs start, so there is no upstream Windows result yet.
Known limitation retained from #165: this fixes cancellation/error delivery before child exit; it does not claim complete Node close-event ordering parity. The stream close event can precede the canceled write callback.