Fix/sigint graceful shutdown (#125)
This commit is contained in:
@@ -1870,28 +1870,29 @@ async function gracefulShutdown(options = {}) {
|
|||||||
|
|
||||||
if (openCodeProcess) {
|
if (openCodeProcess) {
|
||||||
console.log('Stopping OpenCode process...');
|
console.log('Stopping OpenCode process...');
|
||||||
openCodeProcess.kill('SIGTERM');
|
try {
|
||||||
|
openCodeProcess.close();
|
||||||
await new Promise((resolve) => {
|
} catch (error) {
|
||||||
const timeout = setTimeout(() => {
|
console.warn('Error closing OpenCode process:', error);
|
||||||
openCodeProcess.kill('SIGKILL');
|
}
|
||||||
resolve();
|
openCodeProcess = null;
|
||||||
}, SHUTDOWN_TIMEOUT);
|
|
||||||
|
|
||||||
openCodeProcess.on('exit', () => {
|
|
||||||
clearTimeout(timeout);
|
|
||||||
resolve();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (server) {
|
if (server) {
|
||||||
await new Promise((resolve) => {
|
await Promise.race([
|
||||||
server.close(() => {
|
new Promise((resolve) => {
|
||||||
console.log('HTTP server closed');
|
server.close(() => {
|
||||||
resolve();
|
console.log('HTTP server closed');
|
||||||
});
|
resolve();
|
||||||
});
|
});
|
||||||
|
}),
|
||||||
|
new Promise((resolve) => {
|
||||||
|
setTimeout(() => {
|
||||||
|
console.warn('Server close timeout reached, forcing shutdown');
|
||||||
|
resolve();
|
||||||
|
}, SHUTDOWN_TIMEOUT);
|
||||||
|
})
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (uiAuthController) {
|
if (uiAuthController) {
|
||||||
@@ -4781,9 +4782,12 @@ async function main(options = {}) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (attachSignals && !signalsAttached) {
|
if (attachSignals && !signalsAttached) {
|
||||||
process.on('SIGTERM', gracefulShutdown);
|
const handleSignal = async () => {
|
||||||
process.on('SIGINT', gracefulShutdown);
|
await gracefulShutdown();
|
||||||
process.on('SIGQUIT', gracefulShutdown);
|
};
|
||||||
|
process.on('SIGTERM', handleSignal);
|
||||||
|
process.on('SIGINT', handleSignal);
|
||||||
|
process.on('SIGQUIT', handleSignal);
|
||||||
signalsAttached = true;
|
signalsAttached = true;
|
||||||
syncToHmrState();
|
syncToHmrState();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user