mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-16 13:05:14 +03:00
fix(util): kill spawned process groups when opencode exits (#59411)
This commit is contained in:
committed by
GitHub
Unverified
parent
f97f82c96f
commit
e2bc79dc0b
@@ -36,14 +36,20 @@ export const install = Effect.fnUntraced(function* (input: Duration.Input = DEAD
|
||||
started = true
|
||||
fork(expire(signal))
|
||||
}
|
||||
// Closing the terminal sends SIGHUP, whose default action exits without teardown. Treat it as SIGTERM, but only
|
||||
// with a terminal: nohup and the background service have none, and a listener would override nohup's ignore.
|
||||
const onHangup = () => process.kill(process.pid, "SIGTERM")
|
||||
const hangup = process.stdin.isTTY || process.stdout.isTTY
|
||||
const off = () => {
|
||||
process.off("SIGTERM", onSignal)
|
||||
process.off("SIGINT", onSignal)
|
||||
process.off("SIGHUP", onHangup)
|
||||
}
|
||||
yield* Effect.acquireRelease(
|
||||
Effect.sync(() => {
|
||||
process.on("SIGTERM", onSignal)
|
||||
process.on("SIGINT", onSignal)
|
||||
if (hangup) process.on("SIGHUP", onHangup)
|
||||
}),
|
||||
// Once shutdown has started, keep listening: this release can run while a later finalizer is still stuck.
|
||||
() =>
|
||||
|
||||
Reference in New Issue
Block a user