From 801ef14b7eab1a2bb8dc3c06a8d418b0c2c5e630 Mon Sep 17 00:00:00 2001 From: Erik Michelson Date: Mon, 24 Nov 2025 14:28:01 +0100 Subject: [PATCH] fix(shutdown): kill server after timeout when hanging on shutdown When socket.io is not able to close a connection somehow, the code never reaches the final shutdown state but keeps waiting for all connections to be closed. This can cause a high CPU load on failing shutdown. It is very unlikely to happen, except when the server is shut down exactly at the same time a socket is disconnecting and not already marked as disconnected. This change adds a fallback timer which forcefully kills the server after a certain amount of time. Signed-off-by: Erik Michelson --- app.js | 7 +++++++ public/docs/release-notes.md | 3 ++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app.js b/app.js index d3b90e0d..b935306d 100644 --- a/app.js +++ b/app.js @@ -394,6 +394,13 @@ function handleTermSignals () { process.exit(0) } }) + } else { + logger.warn(`Real time server not ready for shutdown, trying again (${currentCleanTry}/${maxCleanTries})...`) + currentCleanTry++ + if (currentCleanTry > maxCleanTries) { + logger.error('Could not save note revisions after shutdown! Exiting.') + process.exit(1) + } } }, 200) } diff --git a/public/docs/release-notes.md b/public/docs/release-notes.md index fcdd91f1..82b9b96c 100644 --- a/public/docs/release-notes.md +++ b/public/docs/release-notes.md @@ -12,7 +12,8 @@ ### Bugfixes - Ignore the healthcheck endpoint in the "too busy" limiter -- Send the referrer origin for YouTube embeddings due to their requirement +- Send the referrer origin for YouTube embeddings due to their requirement +- Force kill the server after a timeout when waiting for the realtime server to close connections on shutdown ## 1.10.3 2025-04-09