Skip to content

fix(node:child_process): cancel pending stdin writes on destroy - #170

Merged
steipete merged 1 commit into
mainfrom
claude/child-stdin-destroy-windows
Oct 14, 2026
Merged

steipete merged 1 commit into
mainfrom
claude/child-stdin-destroy-windows

Conversation

@steipete

@steipete steipete commented Oct 14, 2026 •

Copy link
Copy Markdown

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 ECANCELED error, 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, including child-process-stdio.test.js and the two #165 pending-destroy regressions in child_process.test.ts. Both smoke tests also pass. The selected file lists and child-process test sources are identical to the failing candidate.

Windows proof x64 ARM64
Original f0f3 candidate, run 38553687555: child.stdin.unref releases the stdin writer keep-alive Fails with EPIPE after about 30 s Fails with EPIPE after about 30 s
Guarded candidate: child-process-stdio.test.js Pass Pass
Guarded candidate: child_process.test.ts Pass Pass
Shared compatibility selection 31/31 files pass 31/31 files pass

The 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-issues configuration 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.

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.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-14T12:36:30.975023Z ba89612 PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

@steipete
steipete merged commit 94f8f5f into main Oct 14, 2026
23 of 24 checks passed
@steipete
steipete deleted the claude/child-stdin-destroy-windows branch October 14, 2026 15:32
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