Merge pull request #1545 from hedgedoc/fix/shutdown_loop

This commit is contained in:
David Mehren 2021-08-15 00:04:17 +02:00 committed by GitHub
commit 3175fe18b2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 3 deletions

23
app.js
View file

@ -309,9 +309,15 @@ process.on('uncaughtException', function (err) {
process.exit(1)
})
let alreadyHandlingTermSignals = false
// install exit handler
function handleTermSignals () {
if (alreadyHandlingTermSignals) {
logger.info('Forcefully exiting.')
process.exit(1)
}
logger.info('HedgeDoc has been killed by signal, try to exit gracefully...')
alreadyHandlingTermSignals = true
realtime.maintenance = true
// disconnect all socket.io clients
Object.keys(io.sockets.sockets).forEach(function (key) {
@ -331,17 +337,28 @@ function handleTermSignals () {
}
})
}
const maxCleanTries = 30
let currentCleanTry = 1
const checkCleanTimer = setInterval(function () {
if (realtime.isReady()) {
models.Revision.checkAllNotesRevision(function (err, notes) {
if (err) return logger.error(err)
if (err) {
logger.error('Error while saving note revisions: ' + err)
if (currentCleanTry <= maxCleanTries) {
logger.warn(`Trying again. Try ${currentCleanTry} of ${maxCleanTries}`)
currentCleanTry++
return null
}
logger.error(`Could not save note revisions after ${maxCleanTries} tries! Exiting.`)
process.exit(1)
}
if (!notes || notes.length <= 0) {
clearInterval(checkCleanTimer)
return process.exit(0)
process.exit(0)
}
})
}
}, 100)
}, 200)
}
process.on('SIGINT', handleTermSignals)
process.on('SIGTERM', handleTermSignals)

View file

@ -11,6 +11,7 @@
### Bugfixes
- Fix crash when trying to read the current Git commit on startup
- Fix endless loop on shutdown when HedgeDoc can't connect to the database
## <i class="fa fa-tag"></i> 1.8.2 <i class="fa fa-calendar-o"></i> 2021-05-11