Unverified Commit 43229e4f authored by perryitay's avatar perryitay Committed by GitHub
Browse files

Safe and organized exit when receiving sigterm while loading (#10003)

on the signal handler we are enabling server.shutdown_asap flag instead of just doing `exit()`,
and then catch it on the whileBlockedCron() where we prepare for shutdown correctly.

this is a more ore organized and safe termination, the old approach was missing these for example:
1. removal of the pidfile
2. shutdown event to modules
parent 266d9506
...@@ -1373,6 +1373,14 @@ void whileBlockedCron() { ...@@ -1373,6 +1373,14 @@ void whileBlockedCron() {
latencyEndMonitor(latency); latencyEndMonitor(latency);
latencyAddSampleIfNeeded("while-blocked-cron",latency); latencyAddSampleIfNeeded("while-blocked-cron",latency);
/* We received a SIGTERM during loading, shutting down here in a safe way,
* as it isn't ok doing so inside the signal handler. */
if (server.shutdown_asap && server.loading) {
if (prepareForShutdown(SHUTDOWN_NOSAVE) == C_OK) exit(0);
serverLog(LL_WARNING,"SIGTERM received but errors trying to shut down the server, check the logs for more information");
server.shutdown_asap = 0;
}
} }
extern int ProcessingEventsWhileBlocked; extern int ProcessingEventsWhileBlocked;
...@@ -5587,8 +5595,7 @@ static void sigShutdownHandler(int sig) { ...@@ -5587,8 +5595,7 @@ static void sigShutdownHandler(int sig) {
rdbRemoveTempFile(getpid(), 1); rdbRemoveTempFile(getpid(), 1);
exit(1); /* Exit with an error since this was not a clean shutdown. */ exit(1); /* Exit with an error since this was not a clean shutdown. */
} else if (server.loading) { } else if (server.loading) {
serverLogFromHandler(LL_WARNING, "Received shutdown signal during loading, exiting now."); msg = "Received shutdown signal during loading, scheduling shutdown.";
exit(0);
} }
serverLogFromHandler(LL_WARNING, msg); serverLogFromHandler(LL_WARNING, msg);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment