(label: string, watchdog: WatchdogOptions = {})
| 52 | * SIGKILLed (#1231). |
| 53 | */ |
| 54 | export function installCommandSupervision(label: string, watchdog: WatchdogOptions = {}): CommandSupervision { |
| 55 | // Liveness watchdog: a separate process that SIGKILLs us if our event loop |
| 56 | // stops turning for too long (a wedged synchronous loop). Self-disables on |
| 57 | // CODEGRAPH_NO_WATCHDOG. |
| 58 | const liveness = installMainThreadWatchdog(watchdog); |
| 59 | |
| 60 | // PPID watchdog: detect that the parent (or the host threaded past the |
| 61 | // relaunch shim) died and we've been orphaned, then exit instead of leaking. |
| 62 | const stopParentWatch = watchParent((reason) => { |
| 63 | try { |
| 64 | process.stderr.write(`[CodeGraph ${label}] Parent process exited (${reason}); aborting.\n`); |
| 65 | } catch { /* stderr gone with the parent — exit anyway */ } |
| 66 | process.exit(1); |
| 67 | }); |
| 68 | |
| 69 | let stopped = false; |
| 70 | return { |
| 71 | stop(): void { |
| 72 | if (stopped) return; |
| 73 | stopped = true; |
| 74 | stopParentWatch(); |
| 75 | liveness?.stop(); |
| 76 | }, |
| 77 | }; |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * Call `onLost` once, when the parent — or the host threaded past the |
no test coverage detected