summaryrefslogtreecommitdiff
path: root/ext/node/polyfills/internal/child_process.ts
diff options
context:
space:
mode:
authorNathan Whitaker <17734409+nathanwhit@users.noreply.github.com>2024-10-23 21:50:35 -0700
committerGitHub <noreply@github.com>2024-10-24 04:50:35 +0000
commit27df42f659ae7b77968d31363ade89addb516ea1 (patch)
tree4668ce4fe1b1bb32a4397b511dff46a818eab7a1 /ext/node/polyfills/internal/child_process.ts
parent7c57105cc41cf16c5f48f85d85c7fd9bd3bb4d1f (diff)
fix(ext/node): cancel pending ipc writes on channel close (#26504)
Fixes the issue described in https://github.com/denoland/deno/issues/23882#issuecomment-2423316362. The parent was starting to send a message right before the process would exit, and the channel closed in the middle of the write. Unlike with reads, we weren't cancelling the pending writes, which resulted in a `Broken pipe` error surfacing to the user.
Diffstat (limited to 'ext/node/polyfills/internal/child_process.ts')
-rw-r--r--ext/node/polyfills/internal/child_process.ts19
1 files changed, 15 insertions, 4 deletions
diff --git a/ext/node/polyfills/internal/child_process.ts b/ext/node/polyfills/internal/child_process.ts
index 65d825fd2..cfff1079f 100644
--- a/ext/node/polyfills/internal/child_process.ts
+++ b/ext/node/polyfills/internal/child_process.ts
@@ -1339,7 +1339,7 @@ export function setupChannel(target: any, ipc: number) {
}
}
- process.nextTick(handleMessage, msg);
+ nextTick(handleMessage, msg);
}
} catch (err) {
if (
@@ -1400,7 +1400,7 @@ export function setupChannel(target: any, ipc: number) {
if (!target.connected) {
const err = new ERR_IPC_CHANNEL_CLOSED();
if (typeof callback === "function") {
- process.nextTick(callback, err);
+ nextTick(callback, err);
} else {
nextTick(() => target.emit("error", err));
}
@@ -1416,7 +1416,18 @@ export function setupChannel(target: any, ipc: number) {
.then(() => {
control.unrefCounted();
if (callback) {
- process.nextTick(callback, null);
+ nextTick(callback, null);
+ }
+ }, (err: Error) => {
+ control.unrefCounted();
+ if (err instanceof Deno.errors.Interrupted) {
+ // Channel closed on us mid-write.
+ } else {
+ if (typeof callback === "function") {
+ nextTick(callback, err);
+ } else {
+ nextTick(() => target.emit("error", err));
+ }
}
});
return queueOk[0];
@@ -1433,7 +1444,7 @@ export function setupChannel(target: any, ipc: number) {
target.connected = false;
target[kCanDisconnect] = false;
control[kControlDisconnect]();
- process.nextTick(() => {
+ nextTick(() => {
target.channel = null;
core.close(ipc);
target.emit("disconnect");