New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Gracefully quit on Ctrl+C
#1477
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -115,6 +115,31 @@ module.exports = function() { | |
new Identification((identHandler) => { | ||
manager.init(identHandler, sockets); | ||
}); | ||
|
||
// Handle ctrl+c and kill gracefully | ||
let suicideTimeout = null; | ||
const exitGracefully = function() { | ||
if (suicideTimeout !== null) { | ||
return; | ||
} | ||
|
||
// Forcefully exit after 3 seconds | ||
suicideTimeout = setTimeout(() => process.exit(1), 3000); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe another There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think it's necessary to add a message. |
||
|
||
log.info("Exiting..."); | ||
|
||
// Close all client and IRC connections | ||
manager.clients.forEach((client) => client.quit()); | ||
|
||
// Close http server | ||
server.close(() => { | ||
clearTimeout(suicideTimeout); | ||
process.exit(0); | ||
}); | ||
}; | ||
|
||
process.on("SIGINT", exitGracefully); | ||
process.on("SIGTERM", exitGracefully); | ||
}); | ||
}; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This feels like an unrelated fix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not, we don't want to sign out users on server close.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh woops, I missed that we were already sending sign-out. Sounds good.