summaryrefslogtreecommitdiff
path: root/src/server.c
diff options
context:
space:
mode:
authorperryitay <85821686+perryitay@users.noreply.github.com>2021-12-28 13:25:56 +0200
committerGitHub <noreply@github.com>2021-12-28 13:25:56 +0200
commit43229e4f1028777a7d0e1b44425e3e3cb91ea8e9 (patch)
tree81b1f6ec3aa23439df2bb39b1d2125c85fd11690 /src/server.c
parent266d95066da8082ab569207765bea674fa297404 (diff)
downloadredis-43229e4f1028777a7d0e1b44425e3e3cb91ea8e9.tar.gz
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
Diffstat (limited to 'src/server.c')
-rw-r--r--src/server.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/server.c b/src/server.c
index 046f9ac74..6d531449e 100644
--- a/src/server.c
+++ b/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);