From bbac4fe9577eb85b52396b3e92028909094768b3 Mon Sep 17 00:00:00 2001 From: Anton Golub Date: Tue, 17 Dec 2024 13:27:53 +0300 Subject: [PATCH] fix: apply forced stdio destroy for abort flow only --- src/main/ts/spawn.ts | 8 ++++++-- target/cjs/spawn.cjs | 8 ++++++-- target/esm/spawn.mjs | 8 ++++++-- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/main/ts/spawn.ts b/src/main/ts/spawn.ts index 4b3c7c2..4aa489c 100644 --- a/src/main/ts/spawn.ts +++ b/src/main/ts/spawn.ts @@ -216,6 +216,7 @@ export const invoke = (c: TSpawnCtxNormalized): TSpawnCtxNormalized => { toggleListeners('on', c.ee, c.on) let error: any = null + let aborted = false const opts = buildSpawnOpts(c) const child = c.spawn(c.cmd, c.args, opts) const onAbort = (event: any) => { @@ -227,6 +228,7 @@ export const invoke = (c: TSpawnCtxNormalized): TSpawnCtxNormalized => { child.kill() } } + aborted = true c.ee.emit('abort', event, c) } c.child = child @@ -252,8 +254,10 @@ export const invoke = (c: TSpawnCtxNormalized): TSpawnCtxNormalized => { c.ee.emit('err', error, c) }) .once('exit', () => { - child.stdout?.destroy() - child.stderr?.destroy() + if (aborted) { + child.stdout?.destroy() + child.stderr?.destroy() + } }) .once('close', (status, signal) => { c.fulfilled = { diff --git a/target/cjs/spawn.cjs b/target/cjs/spawn.cjs index 9f58bcd..eb223de 100644 --- a/target/cjs/spawn.cjs +++ b/target/cjs/spawn.cjs @@ -163,6 +163,7 @@ var invoke = (c) => { var _a2, _b2, _c; toggleListeners("on", c.ee, c.on); let error = null; + let aborted = false; const opts = buildSpawnOpts(c); const child = c.spawn(c.cmd, c.args, opts); const onAbort = (event) => { @@ -173,6 +174,7 @@ var invoke = (c) => { child.kill(); } } + aborted = true; c.ee.emit("abort", event, c); }; c.child = child; @@ -194,8 +196,10 @@ var invoke = (c) => { c.ee.emit("err", error, c); }).once("exit", () => { var _a3, _b3; - (_a3 = child.stdout) == null ? void 0 : _a3.destroy(); - (_b3 = child.stderr) == null ? void 0 : _b3.destroy(); + if (aborted) { + (_a3 = child.stdout) == null ? void 0 : _a3.destroy(); + (_b3 = child.stderr) == null ? void 0 : _b3.destroy(); + } }).once("close", (status, signal) => { var _a3; c.fulfilled = { diff --git a/target/esm/spawn.mjs b/target/esm/spawn.mjs index 393d0b4..9fdd72c 100644 --- a/target/esm/spawn.mjs +++ b/target/esm/spawn.mjs @@ -142,6 +142,7 @@ var invoke = (c) => { var _a2, _b2, _c; toggleListeners("on", c.ee, c.on); let error = null; + let aborted = false; const opts = buildSpawnOpts(c); const child = c.spawn(c.cmd, c.args, opts); const onAbort = (event) => { @@ -152,6 +153,7 @@ var invoke = (c) => { child.kill(); } } + aborted = true; c.ee.emit("abort", event, c); }; c.child = child; @@ -173,8 +175,10 @@ var invoke = (c) => { c.ee.emit("err", error, c); }).once("exit", () => { var _a3, _b3; - (_a3 = child.stdout) == null ? void 0 : _a3.destroy(); - (_b3 = child.stderr) == null ? void 0 : _b3.destroy(); + if (aborted) { + (_a3 = child.stdout) == null ? void 0 : _a3.destroy(); + (_b3 = child.stderr) == null ? void 0 : _b3.destroy(); + } }).once("close", (status, signal) => { var _a3; c.fulfilled = {