Repository navigation
fix(ext/node): support numeric FDs in child_process stdio array - #32959
Conversation
005309e to
5ccac4f
Compare
Node.js allows passing raw file descriptors as numbers in the `stdio`
array for `child_process.spawn()`, e.g.:
spawn('cmd', { stdio: ['ignore', 'pipe', 'pipe', fd] })
Previously this failed with `serde_v8 error: invalid type; expected:
enum, got: Number` because `extra_stdio` was typed as `Vec<Stdio>`
which only accepts string variants.
Refactor `StdioOrRid` → `StdioOrFdOrRid` with a new `Fd(i32)` variant
for raw file descriptors. Numbers now deserialize as `Fd` and are
dup2'd to the target fd in the child process on Unix.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
5ccac4f to
b9fe3d9
Compare
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Deno's fs.openSync returns a resource ID on Windows, not a CRT file descriptor. Passing this to libc::get_osfhandle causes a crash (STATUS_STACK_BUFFER_OVERRUN). Skip the test on Windows until Deno's fs.openSync returns real CRT fds. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
ReviewThe type refactor ( A few things to consider:
|
…ship - Fold redundant Rid(_) match arm into _ on Windows - Rename _fd to fd for consistency with Unix loop - Document that the caller retains ownership of raw_fd (not added to fds_to_close) in the Unix Fd path - Verified Deno.Command public API only accepts string stdio values, so the Fd deserialization change doesn't affect it Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…ay (#32959)" (#33017) ## Summary Reverts #32959 (commit ffbe236) which added support for numeric FDs in `child_process` stdio array. The reverted commit changed deserialization of numeric values in stdio config from `Rid(ResourceId)` to `Fd(i32)`, meaning all numeric stdio values are now interpreted as raw OS file descriptors instead of Deno resource IDs. This is a breaking change because Deno's Node-compat `fs.openSync` currently returns Deno resource IDs, not raw file descriptors (unlike Node.js which returns raw FDs). Any code that passes a numeric value from `fs.openSync` (or similar) as a stdio option now calls `dup()` on a wrong/nonexistent OS file descriptor instead of looking it up in Deno's resource table. This was reported as breaking Claude Code installed via Deno -- it could not run Bash at all. #31965 needs to land first (making `fs.openSync` return raw FDs), and then #32959 can be re-landed safely.
Now that `fs.openSync` returns real OS file descriptors (#33039), numeric values in child_process stdio arrays should be treated as raw fds rather than Deno resource IDs. This re-lands the functionality from #32959 (reverted in #33017) with the correct fd-based approach. - Rename `StdioOrRid` to `StdioOrFd`, replace `Rid(ResourceId)` with `Fd(i32)` - `as_stdio()` dups the fd directly (Unix: `libc::dup`, Windows: handle clone) instead of looking up the resource table - `extra_stdio` now accepts `StdioOrFd` so numeric fds work beyond stdin/stdout/stderr - Hardcoded `Rid(1)`/`Rid(2)` for inherit become `Fd(1)`/`Fd(2)` Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
## Summary Now that `fs.openSync` returns real OS file descriptors (#33039), numeric values in child_process stdio arrays should be treated as raw fds rather than Deno resource IDs. This re-lands the functionality from #32959 (reverted in #33017) with the correct fd-based approach. - Rename `StdioOrRid` to `StdioOrFd`, replace `Rid(ResourceId)` with `Fd(i32)` - `as_stdio()` dups the fd directly (`libc::dup` on Unix, handle clone on Windows) instead of looking up the resource table - `extra_stdio` now accepts `StdioOrFd` so numeric fds work beyond stdin/stdout/stderr - Hardcoded `Rid(1)`/`Rid(2)` for inherit become `Fd(1)`/`Fd(2)` - Remove unused `FileResource` import --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
## Summary Now that `fs.openSync` returns real OS file descriptors (#33039), numeric values in child_process stdio arrays should be treated as raw fds rather than Deno resource IDs. This re-lands the functionality from #32959 (reverted in #33017) with the correct fd-based approach. - Rename `StdioOrRid` to `StdioOrFd`, replace `Rid(ResourceId)` with `Fd(i32)` - `as_stdio()` dups the fd directly (`libc::dup` on Unix, handle clone on Windows) instead of looking up the resource table - `extra_stdio` now accepts `StdioOrFd` so numeric fds work beyond stdin/stdout/stderr - Hardcoded `Rid(1)`/`Rid(2)` for inherit become `Fd(1)`/`Fd(2)` - Remove unused `FileResource` import --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Summary
stdioarray forchild_process.spawn(), e.g.spawn('cmd', { stdio: ['ignore', 'pipe', 'pipe', fd] }). This previously failed withserde_v8 error: invalid type; expected: enum, got: NumberStdioOrRid→StdioOrFdOrRidwith a newFd(i32)variant for raw file descriptorsextra_stdionow deserialize asFdand are dup2'd to the target fd in the child process on Unixas_stdio()also handlesFdby dup'ing it into astd::fs::Filefor use with stdin/stdout/stderrTowards #32846