Skip to content

Commit

Permalink
fix: apply forced stdio destroy for abort flow only
Browse files Browse the repository at this point in the history
  • Loading branch information
antongolub committed Dec 17, 2024
1 parent cd32992 commit bbac4fe
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
8 changes: 6 additions & 2 deletions src/main/ts/spawn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -227,6 +228,7 @@ export const invoke = (c: TSpawnCtxNormalized): TSpawnCtxNormalized => {
child.kill()
}
}
aborted = true
c.ee.emit('abort', event, c)
}
c.child = child
Expand All @@ -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 = {
Expand Down
8 changes: 6 additions & 2 deletions target/cjs/spawn.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -173,6 +174,7 @@ var invoke = (c) => {
child.kill();
}
}
aborted = true;
c.ee.emit("abort", event, c);
};
c.child = child;
Expand All @@ -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 = {
Expand Down
8 changes: 6 additions & 2 deletions target/esm/spawn.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -152,6 +153,7 @@ var invoke = (c) => {
child.kill();
}
}
aborted = true;
c.ee.emit("abort", event, c);
};
c.child = child;
Expand All @@ -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 = {
Expand Down

0 comments on commit bbac4fe

Please sign in to comment.