Handle SIGINT in server better by moving DB call to after redis shutdown

This commit is contained in:
Jackson Harper 2024-01-18 12:00:13 +08:00
parent bb55137bb4
commit ee142d3d7c
2 changed files with 6 additions and 4 deletions

View file

@ -36,7 +36,7 @@ export class RedisDataSource {
async shutdown(): Promise<void> {
this.isInitialized = false
try {
await this.workerRedisClient?.disconnect()
await this.workerRedisClient?.quit()
await this.redisClient?.quit()
} catch (err) {
console.error('error while shutting down redis')

View file

@ -190,12 +190,14 @@ const main = async (): Promise<void> => {
listener.timeout = 640 * 1000 // match headersTimeout
process.on('SIGINT', async () => {
await appDataSource.destroy()
console.log('DB connection closed.')
// Shutdown redis before DB because the quit sequence can
// cause appDataSource to get reloaded in the callback
await redisDataSource.shutdown()
console.log('Redis connection closed.')
await appDataSource.destroy()
console.log('DB connection closed.')
process.exit(0)
})
}