fix: validate spawn pid before writing PID file
Add check for undefined child.pid after spawn() to prevent writing invalid PID files when spawn fails. Exit with error code 1 if spawn failed. Removes unnecessary non-null assertion. Phase 2 of PR #458 fixes. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -830,10 +830,16 @@ async function main() {
|
||||
windowsHide: true,
|
||||
env: { ...process.env, CLAUDE_MEM_WORKER_PORT: String(port) }
|
||||
});
|
||||
|
||||
if (child.pid === undefined) {
|
||||
console.error('Failed to spawn worker daemon');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
child.unref();
|
||||
|
||||
// Write PID file
|
||||
writePidFile({ pid: child.pid!, port, startedAt: new Date().toISOString() });
|
||||
writePidFile({ pid: child.pid, port, startedAt: new Date().toISOString() });
|
||||
|
||||
// Wait for health
|
||||
const healthy = await waitForHealth(port, 30000);
|
||||
|
||||
Reference in New Issue
Block a user