Ensure clean shutdown with multiple threads

This commit is contained in:
John Sully 2022-05-24 05:10:18 +00:00
parent 84b37edfcf
commit f60bb34994
3 changed files with 8 additions and 5 deletions

View File

@ -2656,13 +2656,15 @@ int serverCron(struct aeEventLoop *eventLoop, long long id, void *clientData) {
bool fActiveClient = false; bool fActiveClient = false;
while ((ln = listNext(&li)) && !fActiveClient) { while ((ln = listNext(&li)) && !fActiveClient) {
client *c = (client*)listNodeValue(ln); client *c = (client*)listNodeValue(ln);
if (c->flags & (CLIENT_MASTER | CLIENT_SLAVE | CLIENT_BLOCKED | CLIENT_MONITOR)) if (c->flags & CLIENT_IGNORE_SOFT_SHUTDOWN)
continue; continue;
fActiveClient = true; fActiveClient = true;
} }
if (!fActiveClient) { if (!fActiveClient) {
serverLog(LL_WARNING, "All active clients have disconnected while a soft shutdown is pending. Shutting down now."); if (prepareForShutdown(SHUTDOWN_NOFLAGS) == C_OK) {
throw ShutdownException(); 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; return;
} }
if (g_pserver->soft_shutdown) { if (g_pserver->soft_shutdown && !(c->flags & CLIENT_IGNORE_SOFT_SHUTDOWN)) {
addReplyError(c, "-SHUTDOWN PENDING"); addReplyError(c, "-SHUTDOWN PENDING");
return; return;
} }

View File

@ -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_AOF_PROP (1<<19) /* Don't propagate to AOF. */
#define CLIENT_PREVENT_REPL_PROP (1<<20) /* Don't propagate to slaves. */ #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_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 #define CLIENT_PENDING_WRITE (1<<21) /* Client has output to send but a write
handler is yet not installed. */ handler is yet not installed. */
#define CLIENT_REPLY_OFF (1<<22) /* Don't send replies to client. */ #define CLIENT_REPLY_OFF (1<<22) /* Don't send replies to client. */

View File

@ -23,7 +23,7 @@ start_server {tags {"soft_shutdown"} } {
} }
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" assert_equal [r shutdown soft] "OK"
r set test val r set test val
assert_equal [r get test] {val} assert_equal [r get test] {val}