fix(process): allow unref'd child processes to outlive parent#32563
Merged
bartlomieju merged 3 commits intomainfrom Mar 17, 2026
Merged
fix(process): allow unref'd child processes to outlive parent#32563bartlomieju merged 3 commits intomainfrom
bartlomieju merged 3 commits intomainfrom
Conversation
Previously, calling `unref()` on a child process spawned via `node:child_process` or `Deno.ChildProcess` would still kill the child when the parent exited. This happened because tokio's `kill_on_drop(true)` was set at spawn time with no way to disable it later. This commit replaces tokio/deno_subprocess_windows's `kill_on_drop` with a custom `Drop` implementation on `ChildResource` that kills the child by PID only when a `kill_on_drop` flag is true. New ops `op_spawn_child_ref` and `op_spawn_child_unref` toggle this flag, and are called from `ChildProcess.ref()` and `ChildProcess.unref()` in JS. Closes #21446 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
kajukitli
approved these changes
Mar 7, 2026
Contributor
kajukitli
left a comment
There was a problem hiding this comment.
lgtm — good fix for Node.js unref() semantics
the approach is correct:
- custom
Dropimpl onChildResourceinstead of tokio'skill_on_drop(true) kill_on_drop: Cell<bool>toggled byop_spawn_child_ref/unref- sends SIGKILL on drop only if
kill_on_dropis true
test coverage is solid — spawns child, calls unref, parent exits, verifies child wrote marker file
On Windows, non-detached children are assigned to a global job object with JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE, so they are always terminated when the parent exits — regardless of unref(). This is a Windows OS-level behaviour that cannot be changed after spawn. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The `multi_test` schema does not support `if` at the top level — it must be inside the individual test definition (`single_or_multi_step_test`). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
child_process.unref()killing the child process when the parent exits, instead of letting it continue running independently (Node.js behavior)kill_on_drop(true)with a customDroponChildResourcethat respects a togglablekill_on_dropflagop_spawn_child_ref/op_spawn_child_unrefops to control the flag from JSref()/unref()child_processpolyfill delegates toDeno.ChildProcess, so it gets the fix automaticallyTest plan
child_process_unref_survives— parent spawns child, callsunref(), exits; verifies child wrote a marker filechild_processspec tests pass (18/18)cargo check, format, and lint passCloses #21446
🤖 Generated with Claude Code