Skip to content

Commit 1486a08

Browse files
manusaclaude
andcommitted
fix(npm): use spawn with signal handling for graceful shutdown
Replace execFileSync with spawn and add proper signal handling for SIGTERM, SIGINT, and SIGHUP. This ensures the child process is properly terminated when the wrapper receives a signal and returns correct exit codes based on the termination signal. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent f3f7085 commit 1486a08

1 file changed

Lines changed: 21 additions & 1 deletion

File tree

npm/podman-mcp-server/bin/index.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,27 @@ const resolveBinaryPath = () => {
2121
}
2222
};
2323

24-
childProcess.execFileSync(resolveBinaryPath(), process.argv.slice(2), {
24+
const child = childProcess.spawn(resolveBinaryPath(), process.argv.slice(2), {
2525
stdio: 'inherit',
2626
});
2727

28+
const handleSignal = () => (signal) => {
29+
console.log(`Received ${signal}, terminating child process...`);
30+
if (child && !child.killed) {
31+
child.kill(signal);
32+
}
33+
};
34+
35+
['SIGTERM', 'SIGINT', 'SIGHUP'].forEach((signal) => {
36+
process.on(signal, handleSignal(signal));
37+
});
38+
39+
child.on('close', (code, signal) => {
40+
if (signal) {
41+
console.log(`Child process terminated by signal: ${signal}`);
42+
process.exit(128 + (signal === 'SIGTERM' ? 15 : signal === 'SIGINT' ? 2 : 1));
43+
} else {
44+
process.exit(code || 0);
45+
}
46+
});
47+

0 commit comments

Comments
 (0)