summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDivy Srivastava <dj.srivastava23@gmail.com>2023-12-20 07:55:09 +0530
committerGitHub <noreply@github.com>2023-12-20 07:55:09 +0530
commit26cf06ed9f5c0ffa42afff3dbe29533ddcb2fbf7 (patch)
treecf834709f662c7ce0cdd17813837b45b9fea9e9c
parent5aa27c45f1cae6f0121e0860cd4be329ced887a6 (diff)
fix(node): child_process kill cancel pending IPC reads (#21647)
-rw-r--r--cli/tests/unit_node/child_process_test.ts23
-rw-r--r--ext/node/polyfills/internal/child_process.ts4
2 files changed, 27 insertions, 0 deletions
diff --git a/cli/tests/unit_node/child_process_test.ts b/cli/tests/unit_node/child_process_test.ts
index 79617cf3d..421e66dfd 100644
--- a/cli/tests/unit_node/child_process_test.ts
+++ b/cli/tests/unit_node/child_process_test.ts
@@ -731,3 +731,26 @@ Deno.test(function spawnSyncExitNonZero() {
assertEquals(ret.status, 22);
});
+
+// https://github.com/denoland/deno/issues/21630
+Deno.test(async function forkIpcKillDoesNotHang() {
+ const testdataDir = path.join(
+ path.dirname(path.fromFileUrl(import.meta.url)),
+ "testdata",
+ );
+ const script = path.join(
+ testdataDir,
+ "node_modules",
+ "foo",
+ "index.js",
+ );
+ const p = Promise.withResolvers<void>();
+ const cp = CP.fork(script, [], {
+ cwd: testdataDir,
+ stdio: ["inherit", "inherit", "inherit", "ipc"],
+ });
+ cp.on("close", () => p.resolve());
+ cp.kill();
+
+ await p.promise;
+});
diff --git a/ext/node/polyfills/internal/child_process.ts b/ext/node/polyfills/internal/child_process.ts
index 0e93e22d3..39c7633e4 100644
--- a/ext/node/polyfills/internal/child_process.ts
+++ b/ext/node/polyfills/internal/child_process.ts
@@ -296,6 +296,10 @@ export class ChildProcess extends EventEmitter {
throw err;
}
}
+
+ /* Cancel any pending IPC I/O */
+ this.disconnect?.();
+
this.killed = true;
this.signalCode = denoSignal;
return this.killed;