mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
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:
parent
1b84f005cc
commit
3e18c06204
1 changed files with 17 additions and 4 deletions
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue