Skip to content

Commit 66ded0c

Browse files
committed
fix(line): keep liveness check alive when ps is unavailable
Use the full command line for the pid-reuse guard and treat a ps failure as alive — kill(0) is the primary signal. Previously a missing or failing ps turned a live daemon into a stale pidfile, which could double-start the daemon; it also broke the liveness test on CI runners where ps output differs from the local environment.
1 parent 11ae549 commit 66ded0c

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

‎apps/scream-code/src/line/pidfile.ts‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,17 +138,20 @@ async function isProcessAlive(pid: number): Promise<boolean> {
138138
if (code === 'EPERM') return true; // exists, owned by another user
139139
return false; // ESRCH — no such process
140140
}
141-
// PID reuse guard: the pid is alive, but is it a line daemon? Check the
142-
// process name on unix (`ps` is unavailable on Windows).
141+
// PID reuse guard: the pid is alive, but is it a line daemon? Match the full
142+
// command line (works on every POSIX platform; `comm` is kernel-truncated
143+
// and varies between environments). kill(0) stays the primary signal — an
144+
// unavailable `ps` must not turn a live daemon into a "dead" one.
143145
if (process.platform === 'win32') return true;
144146
try {
145-
const { stdout } = await execFileAsync('ps', ['-p', String(pid), '-o', 'comm='], {
147+
const { stdout } = await execFileAsync('ps', ['-p', String(pid), '-o', 'command='], {
146148
timeout: 3_000,
147149
});
148-
const comm = stdout.trim().toLowerCase();
149-
return comm.includes('node') || comm.includes('scream') || comm.length === 0;
150+
const commandLine = stdout.trim().toLowerCase();
151+
if (commandLine === '') return true;
152+
return commandLine.includes('node') || commandLine.includes('scream');
150153
} catch {
151-
return false; // process exited between kill(0) and ps
154+
return true; // `ps` unavailable — trust kill(0)
152155
}
153156
}
154157

0 commit comments

Comments
 (0)