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
This commit is contained in:
parent
266d95066d
commit
43229e4f10
11
src/server.c
11
src/server.c
@ -1373,6 +1373,14 @@ void whileBlockedCron() {
|
||||
|
||||
latencyEndMonitor(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;
|
||||
@ -5587,8 +5595,7 @@ static void sigShutdownHandler(int sig) {
|
||||
rdbRemoveTempFile(getpid(), 1);
|
||||
exit(1); /* Exit with an error since this was not a clean shutdown. */
|
||||
} else if (server.loading) {
|
||||
serverLogFromHandler(LL_WARNING, "Received shutdown signal during loading, exiting now.");
|
||||
exit(0);
|
||||
msg = "Received shutdown signal during loading, scheduling shutdown.";
|
||||
}
|
||||
|
||||
serverLogFromHandler(LL_WARNING, msg);
|
||||
|
Loading…
x
Reference in New Issue
Block a user