mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-25 03:06:31 -05:00
Merge pull request #1545 from hedgedoc/fix/shutdown_loop
This commit is contained in:
commit
3175fe18b2
2 changed files with 21 additions and 3 deletions
23
app.js
23
app.js
|
@ -309,9 +309,15 @@ process.on('uncaughtException', function (err) {
|
||||||
process.exit(1)
|
process.exit(1)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
let alreadyHandlingTermSignals = false
|
||||||
// install exit handler
|
// install exit handler
|
||||||
function handleTermSignals () {
|
function handleTermSignals () {
|
||||||
|
if (alreadyHandlingTermSignals) {
|
||||||
|
logger.info('Forcefully exiting.')
|
||||||
|
process.exit(1)
|
||||||
|
}
|
||||||
logger.info('HedgeDoc has been killed by signal, try to exit gracefully...')
|
logger.info('HedgeDoc has been killed by signal, try to exit gracefully...')
|
||||||
|
alreadyHandlingTermSignals = true
|
||||||
realtime.maintenance = true
|
realtime.maintenance = true
|
||||||
// disconnect all socket.io clients
|
// disconnect all socket.io clients
|
||||||
Object.keys(io.sockets.sockets).forEach(function (key) {
|
Object.keys(io.sockets.sockets).forEach(function (key) {
|
||||||
|
@ -331,17 +337,28 @@ function handleTermSignals () {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
const maxCleanTries = 30
|
||||||
|
let currentCleanTry = 1
|
||||||
const checkCleanTimer = setInterval(function () {
|
const checkCleanTimer = setInterval(function () {
|
||||||
if (realtime.isReady()) {
|
if (realtime.isReady()) {
|
||||||
models.Revision.checkAllNotesRevision(function (err, notes) {
|
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) {
|
if (!notes || notes.length <= 0) {
|
||||||
clearInterval(checkCleanTimer)
|
clearInterval(checkCleanTimer)
|
||||||
return process.exit(0)
|
process.exit(0)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}, 100)
|
}, 200)
|
||||||
}
|
}
|
||||||
process.on('SIGINT', handleTermSignals)
|
process.on('SIGINT', handleTermSignals)
|
||||||
process.on('SIGTERM', handleTermSignals)
|
process.on('SIGTERM', handleTermSignals)
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
|
|
||||||
### Bugfixes
|
### Bugfixes
|
||||||
- Fix crash when trying to read the current Git commit on startup
|
- 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
|
## <i class="fa fa-tag"></i> 1.8.2 <i class="fa fa-calendar-o"></i> 2021-05-11
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue