Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: implement child_process IPC #21490

Merged
merged 37 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
11d3db3
Initial commit
littledivy Dec 6, 2023
2c5c6f8
More stuff
littledivy Dec 6, 2023
cb08343
Works
littledivy Dec 7, 2023
6d2cbdd
x
littledivy Dec 7, 2023
99384ca
Add tests
littledivy Dec 7, 2023
a0db846
review + redundant use of Rc
littledivy Dec 8, 2023
099001e
refactor resource
littledivy Dec 8, 2023
c2e0835
improve reader
littledivy Dec 8, 2023
9d96671
Fix disconnect
littledivy Dec 8, 2023
9c91aab
lint
littledivy Dec 8, 2023
7920ce9
cfg unix
littledivy Dec 8, 2023
799a9fb
win lint
littledivy Dec 8, 2023
c1acfb5
fix
littledivy Dec 8, 2023
d071fd8
x
littledivy Dec 9, 2023
eb7029c
faster
littledivy Dec 10, 2023
ce3865a
x
littledivy Dec 10, 2023
906006f
lint
littledivy Dec 10, 2023
dc1f96c
Merge branch 'main' of github.com:denoland/deno into node_ipc
littledivy Dec 10, 2023
a34d652
stuff
littledivy Dec 10, 2023
a70d90a
Add tests
littledivy Dec 10, 2023
3715227
gate simd mod
littledivy Dec 10, 2023
0b1edf5
x
littledivy Dec 10, 2023
6827225
Delete cli/tests/node_compat/require.ts
littledivy Dec 10, 2023
d89007e
x
littledivy Dec 10, 2023
2b63519
fix windows lint
littledivy Dec 10, 2023
48b7b36
Fx
littledivy Dec 10, 2023
dd518fb
Sdt
littledivy Dec 10, 2023
b96a507
fmt config.jsonc
littledivy Dec 11, 2023
ae04e52
x
littledivy Dec 11, 2023
a7581d7
fmt
littledivy Dec 11, 2023
735f799
x
littledivy Dec 11, 2023
9a74269
fix hang
littledivy Dec 12, 2023
64c1d84
Fix
littledivy Dec 12, 2023
76f8b46
fix
littledivy Dec 13, 2023
8cca33a
x
littledivy Dec 13, 2023
6ef9270
x
littledivy Dec 13, 2023
4c1f790
x
littledivy Dec 13, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
145 changes: 145 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions cli/args/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -881,6 +881,17 @@ impl CliOptions {
.map(Some)
}

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

pub fn resolve_main_module(&self) -> Result<ModuleSpecifier, AnyError> {
match &self.flags.subcommand {
DenoSubcommand::Bundle(bundle_flags) => {
Expand Down
1 change: 1 addition & 0 deletions cli/factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,7 @@ impl CliFactory {
self.maybe_lockfile().clone(),
self.feature_checker().clone(),
self.create_cli_main_worker_options()?,
self.options.node_ipc_fd(),
))
}

Expand Down
1 change: 1 addition & 0 deletions cli/standalone/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,7 @@ pub async fn run(
unstable: metadata.unstable,
maybe_root_package_json_deps: package_json_deps_provider.deps().cloned(),
},
None,
);

v8_set_flags(construct_v8_flags(&[], &metadata.v8_flags, vec![]));
Expand Down
18 changes: 7 additions & 11 deletions cli/tests/node_compat/config.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@
"test-child-process-execfile.js",
"test-child-process-execsync-maxbuf.js",
"test-child-process-exit-code.js",
// TODO(littledivy): windows ipc streams not yet implemented
"test-child-process-fork-ref.js",
"test-child-process-fork-ref2.js",
"test-child-process-ipc-next-tick.js",
"test-child-process-ipc.js",
"test-child-process-spawnsync-env.js",
"test-child-process-stdio-inherit.js",
Expand Down Expand Up @@ -110,9 +114,7 @@
"test-zlib-zero-windowBits.js"
],
"pummel": [],
"sequential": [
"test-child-process-exit.js"
]
"sequential": ["test-child-process-exit.js"]
},
"tests": {
"common": [
Expand All @@ -139,11 +141,7 @@
"print-chars.js",
"x.txt"
],
"fixtures/keys": [
"agent1-cert.pem",
"agent1-key.pem",
"ca1-cert.pem"
],
"fixtures/keys": ["agent1-cert.pem", "agent1-key.pem", "ca1-cert.pem"],
"internet": [
"test-dns-any.js",
"test-dns-idna2008.js",
Expand Down Expand Up @@ -696,9 +694,7 @@
"test-tty-stdout-end.js"
],
"pummel": [],
"sequential": [
"test-child-process-exit.js"
]
"sequential": ["test-child-process-exit.js"]
},
"windowsIgnore": {
"parallel": [
Expand Down
72 changes: 72 additions & 0 deletions cli/tests/node_compat/test/parallel/test-child-process-fork-ref.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file

// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 18.12.1
// This file is automatically generated by `tools/node_compat/setup.ts`. Do not modify this file manually.

// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.

'use strict';

// Ignore on Windows.
if (process.platform === 'win32') {
process.exit(0);
}

require('../common');
const assert = require('assert');
const fork = require('child_process').fork;

if (process.argv[2] === 'child') {
process.send('1');

// Check that child don't instantly die
setTimeout(function() {
process.send('2');
}, 200);

process.on('disconnect', function() {
process.stdout.write('3');
});

} else {
const child = fork(__filename, ['child'], { silent: true });

const ipc = [];
let stdout = '';

child.on('message', function(msg) {
ipc.push(msg);

if (msg === '2') child.disconnect();
});

child.stdout.on('data', function(chunk) {
stdout += chunk;
});

child.once('exit', function() {
assert.deepStrictEqual(ipc, ['1', '2']);
assert.strictEqual(stdout, '3');
});
}
Loading