Skip to content

Commit

Permalink
fix: release on abort signal handler
Browse files Browse the repository at this point in the history
  • Loading branch information
antongolub committed Sep 5, 2024
1 parent b8ec123 commit e852e6c
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/main/ts/spawn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,7 @@ export const invoke = (c: TSpawnCtxNormalized): TSpawnCtxNormalized => {
let error: any = null
const opts = buildSpawnOpts(c)
const child = c.spawn(c.cmd, c.args, opts)
c.child = child

c.ee.emit('start', child, c)

opts.signal?.addEventListener('abort', event => {
const onAbort = (event: any) => {
if (opts.detached && child.pid) {
try {
// https://github.com/nodejs/node/issues/51766
Expand All @@ -198,7 +194,13 @@ export const invoke = (c: TSpawnCtxNormalized): TSpawnCtxNormalized => {
}
}
c.ee.emit('abort', event, c)
})
opts.signal.removeEventListener('abort', onAbort)
}
c.child = child

c.ee.emit('start', child, c)

opts.signal?.addEventListener('abort', onAbort)
processInput(child, c.input || c.stdin)

child.stdout?.on('data', d => {
Expand Down

0 comments on commit e852e6c

Please sign in to comment.