Skip to content

Commit 942123c

Browse files
authored
fix: misc signal cleanup (#51)
- Fix test msg - Remove proc 'exit' handler during interrupt This code was a no-op as spawn.js does not emit `exit` events. This is actually good, because were it to be working, it would result in a race condition when a child exits non-zero: 1. The lifecycle promise would be rejected, leading to log output and a possible pnpm exit 2. This hook would force node to exit 0 immediately. - Fix the listener removals when child exits.
1 parent 06ddfa6 commit 942123c

File tree

2 files changed

+3
-5
lines changed

2 files changed

+3
-5
lines changed

index.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -318,8 +318,9 @@ function runCmd_ (cmd, pkg, env, wd, opts, stage, unsafe, uid, gid, cb_) {
318318
er.pkgname = pkg.name
319319
}
320320
process.removeListener('SIGTERM', procKill)
321-
process.removeListener('SIGTERM', procInterrupt)
322321
process.removeListener('SIGINT', procKill)
322+
process.removeListener('SIGINT', procInterrupt)
323+
process.removeListener('exit', procKill)
323324
return cb(er)
324325
}
325326
let called = false
@@ -330,9 +331,6 @@ function runCmd_ (cmd, pkg, env, wd, opts, stage, unsafe, uid, gid, cb_) {
330331
}
331332
function procInterrupt () {
332333
proc.kill('SIGINT')
333-
proc.on('exit', () => {
334-
process.exit()
335-
})
336334
process.once('SIGINT', procKill)
337335
}
338336
}

test/fixtures/count-to-10/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"version": "1.0.0",
44
"scripts": {
55
"postinstall": "node postinstall",
6-
"signal-abrt": "echo 'signal-exit script' && kill -s ABRT $$",
6+
"signal-abrt": "echo 'signal-abrt script' && kill -s ABRT $$",
77
"signal-int": "echo 'signal-int script' && kill -s INT $$"
88
}
99
}

0 commit comments

Comments
 (0)