Merge pull request #16675 from overleaf/bg-clsi-timeout-filestore-graceful-shutdown-part-ii

Extend filestore graceful shutdown

GitOrigin-RevId: 26cb556c289e153089236dee51ec0e86a9e9d5d0
This commit is contained in:
Brian Gough 2024-07-05 10:36:32 +01:00 committed by Copybot
parent 1b84f005cc
commit 3e18c06204

View file

@ -161,9 +161,10 @@ app.use(RequestLogger.errorHandler)
const port = settings.internal.filestore.port || 3009
const host = settings.internal.filestore.host || '0.0.0.0'
let server = null
if (!module.parent) {
// Called directly
app.listen(port, host, error => {
server = app.listen(port, host, error => {
if (error) {
logger.error({ err: error }, 'Error starting Filestore')
throw error
@ -189,10 +190,22 @@ function handleShutdownSignal(signal) {
}
settings.shuttingDown = true
settings.shutDownTime = Date.now()
setTimeout(() => {
logger.info({ signal }, 'shutting down')
// stop accepting new connections, the callback is called when existing connections have finished
server.close(() => {
logger.info({ signal }, 'server closed')
process.exit()
}, settings.gracefulShutdownDelayInMs)
})
// close idle http keep-alive connections
server.closeIdleConnections()
setTimeout(() => {
logger.info({ signal }, 'shutdown timed out, exiting')
// close all connections immediately
server.closeAllConnections()
// exit after a short delay to allow for cleanup
setTimeout(() => {
process.exit()
}, 100)
}, settings.delayShutdownMs)
}
process.on('SIGTERM', handleShutdownSignal)