Prevent server crash on mongo unhandled rejection (#771)

Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
This commit is contained in:
Andrey Sobolev 2022-01-06 18:10:52 +07:00 committed by GitHub
parent 4328fdee9b
commit c53647b7e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -33,10 +33,15 @@ if (elasticUrl === undefined) {
const shutdown = start(url, elasticUrl, 3333) const shutdown = start(url, elasticUrl, 3333)
const close = (): void => { const close = (): void => {
console.error(new Error().stack) console.trace('Exiting from server')
console.log('Shutdown request accepted') console.log('Shutdown request accepted')
shutdown() shutdown()
process.exit(0) process.exit(0)
} }
process.on('unhandledRejection', (reason, promise) => {
console.log('Unhandled Rejection at:', promise, 'reason:', reason)
})
process.on('SIGINT', close) process.on('SIGINT', close)
process.on('SIGTERM', close) process.on('SIGTERM', close)