Skip to content

Commit 55fac9f

Browse files
authored
fix(node): child_process IPC on Windows (#21597)
This PR implements the child_process IPC pipe between parent and child. The implementation uses Windows named pipes created by parent and passes the inheritable file handle to the child. I've also replace parts of the initial implementation which passed the raw parent fd to JS with resource ids instead. This way no file handle is exposed to the JS land (both parent and child). `IpcJsonStreamResource` can stream upto 800MB/s of JSON data on Win 11 AMD Ryzen 7 16GB (without `memchr` vectorization)
1 parent aefa205 commit 55fac9f

File tree

10 files changed

+258
-93
lines changed

10 files changed

+258
-93
lines changed

Diff for: Cargo.lock

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: cli/args/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -917,12 +917,12 @@ impl CliOptions {
917917
.map(Some)
918918
}
919919

920-
pub fn node_ipc_fd(&self) -> Option<i32> {
920+
pub fn node_ipc_fd(&self) -> Option<i64> {
921921
let maybe_node_channel_fd = std::env::var("DENO_CHANNEL_FD").ok();
922922
if let Some(node_channel_fd) = maybe_node_channel_fd {
923923
// Remove so that child processes don't inherit this environment variable.
924924
std::env::remove_var("DENO_CHANNEL_FD");
925-
node_channel_fd.parse::<i32>().ok()
925+
node_channel_fd.parse::<i64>().ok()
926926
} else {
927927
None
928928
}

Diff for: cli/worker.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ struct SharedWorkerState {
124124
maybe_inspector_server: Option<Arc<InspectorServer>>,
125125
maybe_lockfile: Option<Arc<Mutex<Lockfile>>>,
126126
feature_checker: Arc<FeatureChecker>,
127-
node_ipc: Option<i32>,
127+
node_ipc: Option<i64>,
128128
}
129129

130130
impl SharedWorkerState {
@@ -404,7 +404,7 @@ impl CliMainWorkerFactory {
404404
maybe_lockfile: Option<Arc<Mutex<Lockfile>>>,
405405
feature_checker: Arc<FeatureChecker>,
406406
options: CliMainWorkerOptions,
407-
node_ipc: Option<i32>,
407+
node_ipc: Option<i64>,
408408
) -> Self {
409409
Self {
410410
shared: Arc::new(SharedWorkerState {

Diff for: ext/node/Cargo.toml

+4
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,7 @@ url.workspace = true
7474
winapi.workspace = true
7575
x25519-dalek = "2.0.0"
7676
x509-parser = "0.15.0"
77+
78+
[target.'cfg(windows)'.dependencies]
79+
windows-sys.workspace = true
80+
winapi = { workspace = true, features = ["consoleapi"] }

Diff for: ext/node/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ mod polyfill;
3131
mod resolution;
3232

3333
pub use ops::ipc::ChildPipeFd;
34+
pub use ops::ipc::IpcJsonStreamResource;
3435
pub use ops::v8::VM_CONTEXT_INDEX;
3536
pub use package_json::PackageJson;
3637
pub use path::PathClean;
@@ -307,7 +308,6 @@ deno_core::extension!(deno_node,
307308
ops::require::op_require_break_on_next_statement,
308309
ops::util::op_node_guess_handle_type,
309310
ops::crypto::op_node_create_private_key,
310-
ops::ipc::op_node_ipc_pipe,
311311
ops::ipc::op_node_child_ipc_pipe,
312312
ops::ipc::op_node_ipc_write,
313313
ops::ipc::op_node_ipc_read,

0 commit comments

Comments
 (0)