fix: clean up signal handlers on restart
Signed-off-by: Erik Price <github@erikprice.net>
This commit is contained in:
parent
32d925bf0b
commit
d2e0134939
1 changed files with 11 additions and 5 deletions
|
|
@ -602,11 +602,8 @@ export function server(opts) {
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
process.on('SIGINT', () => {
|
const handleSIGINT = () => process.exit();
|
||||||
process.exit();
|
const handleSIGHUP = () => {
|
||||||
});
|
|
||||||
|
|
||||||
process.on('SIGHUP', () => {
|
|
||||||
console.log('Stopping server and reloading config');
|
console.log('Stopping server and reloading config');
|
||||||
|
|
||||||
running.server.shutdown(() => {
|
running.server.shutdown(() => {
|
||||||
|
|
@ -614,6 +611,15 @@ export function server(opts) {
|
||||||
running.server = restarted.server;
|
running.server = restarted.server;
|
||||||
running.app = restarted.app;
|
running.app = restarted.app;
|
||||||
});
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
process.on('SIGINT', handleSIGINT);
|
||||||
|
process.on('SIGHUP', handleSIGHUP);
|
||||||
|
|
||||||
|
// Clean up when we close the server to prevent listener leaks on restart
|
||||||
|
running.server.on('close', () => {
|
||||||
|
process.removeListener('SIGINT', handleSIGINT);
|
||||||
|
process.removeListener('SIGHUP', handleSIGHUP);
|
||||||
});
|
});
|
||||||
|
|
||||||
return running;
|
return running;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue