diff --git a/src/server.cpp b/src/server.cpp index f3bcafd5b..fc5680d28 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -2656,13 +2656,15 @@ int serverCron(struct aeEventLoop *eventLoop, long long id, void *clientData) { bool fActiveClient = false; while ((ln = listNext(&li)) && !fActiveClient) { client *c = (client*)listNodeValue(ln); - if (c->flags & (CLIENT_MASTER | CLIENT_SLAVE | CLIENT_BLOCKED | CLIENT_MONITOR)) + if (c->flags & CLIENT_IGNORE_SOFT_SHUTDOWN) continue; fActiveClient = true; } if (!fActiveClient) { - serverLog(LL_WARNING, "All active clients have disconnected while a soft shutdown is pending. Shutting down now."); - throw ShutdownException(); + if (prepareForShutdown(SHUTDOWN_NOFLAGS) == C_OK) { + serverLog(LL_WARNING, "All active clients have disconnected while a soft shutdown is pending. Shutting down now."); + throw ShutdownException(); + } } } @@ -5315,7 +5317,7 @@ void pingCommand(client *c) { return; } - if (g_pserver->soft_shutdown) { + if (g_pserver->soft_shutdown && !(c->flags & CLIENT_IGNORE_SOFT_SHUTDOWN)) { addReplyError(c, "-SHUTDOWN PENDING"); return; } diff --git a/src/server.h b/src/server.h index 7b101b24b..d60e81b5d 100644 --- a/src/server.h +++ b/src/server.h @@ -508,6 +508,7 @@ extern int configOOMScoreAdjValuesDefaults[CONFIG_OOM_COUNT]; #define CLIENT_PREVENT_AOF_PROP (1<<19) /* Don't propagate to AOF. */ #define CLIENT_PREVENT_REPL_PROP (1<<20) /* Don't propagate to slaves. */ #define CLIENT_PREVENT_PROP (CLIENT_PREVENT_AOF_PROP|CLIENT_PREVENT_REPL_PROP) +#define CLIENT_IGNORE_SOFT_SHUTDOWN (CLIENT_MASTER | CLIENT_SLAVE | CLIENT_BLOCKED | CLIENT_MONITOR) #define CLIENT_PENDING_WRITE (1<<21) /* Client has output to send but a write handler is yet not installed. */ #define CLIENT_REPLY_OFF (1<<22) /* Don't send replies to client. */ diff --git a/tests/unit/soft_shutdown.tcl b/tests/unit/soft_shutdown.tcl index 560ff7eb5..893a988f4 100644 --- a/tests/unit/soft_shutdown.tcl +++ b/tests/unit/soft_shutdown.tcl @@ -23,7 +23,7 @@ start_server {tags {"soft_shutdown"} } { } start_server {tags {"soft_shutdown"} } { - test {soft shutdown prevents allows commands to execute while waiting} { + test {soft shutdown allows commands to execute while waiting} { assert_equal [r shutdown soft] "OK" r set test val assert_equal [r get test] {val}