summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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;