Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions src/blocked.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,17 @@ void processUnblockedClients(void) {
listDelNode(server.unblocked_clients,ln);
c->flags &= ~CLIENT_UNBLOCKED;

/* Reset the client for a new query, unless the client has pending command to process. */
if (!(c->flags & CLIENT_PENDING_COMMAND)) {
freeClientOriginalArgv(c);
/* Clients that are not blocked on keys are not reprocessed so we must
* call reqresAppendResponse here (for clients blocked on key,
* unblockClientOnKey is called, which eventually calls processCommand,
* which calls reqresAppendResponse) */
reqresAppendResponse(c);
resetClient(c);
}

if (c->flags & CLIENT_MODULE) {
if (!(c->flags & CLIENT_BLOCKED)) {
moduleCallCommandUnblockedHandler(c);
Expand Down Expand Up @@ -191,17 +202,6 @@ void unblockClient(client *c, int queue_for_reprocessing) {
serverPanic("Unknown btype in unblockClient().");
}

/* Reset the client for a new query, unless the client has pending command to process
* or in case a shutdown operation was canceled and we are still in the processCommand sequence */
if (!(c->flags & CLIENT_PENDING_COMMAND) && c->bstate.btype != BLOCKED_SHUTDOWN) {
freeClientOriginalArgv(c);
/* Clients that are not blocked on keys are not reprocessed so we must
* call reqresAppendResponse here (for clients blocked on key,
* unblockClientOnKey is called, which eventually calls processCommand,
* which calls reqresAppendResponse) */
reqresAppendResponse(c);
resetClient(c);
}

/* Clear the flags, and put the client in the unblocked list so that
* we'll process new commands in its query buffer ASAP. */
Expand Down Expand Up @@ -266,6 +266,7 @@ void replyToClientsBlockedOnShutdown(void) {
while((ln = listNext(&li))) {
client *c = listNodeValue(ln);
if (c->flags & CLIENT_BLOCKED && c->bstate.btype == BLOCKED_SHUTDOWN) {
c->duration = 0;
addReplyError(c, "Errors trying to SHUTDOWN. Check logs.");
unblockClient(c, 1);
}
Expand Down
2 changes: 1 addition & 1 deletion src/networking.c
Original file line number Diff line number Diff line change
Expand Up @@ -2893,7 +2893,7 @@ int processInputBuffer(client *c) {
/* Keep processing while there is something in the input buffer */
while(c->qb_pos < sdslen(c->querybuf)) {
/* Immediately abort if the client is in the middle of something. */
if (c->flags & CLIENT_BLOCKED) break;
if (c->flags & CLIENT_BLOCKED || c->flags & CLIENT_UNBLOCKED) break;

/* Don't process more buffers from clients that have already pending
* commands to execute in c->argv. */
Expand Down
6 changes: 6 additions & 0 deletions tests/integration/shutdown.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,12 @@ test "Shutting down master waits for replica then fails" {
catch { $rd2 read } e2
assert_match "*Errors trying to SHUTDOWN. Check logs*" $e1
assert_match "*Errors trying to SHUTDOWN. Check logs*" $e2

# Verify that after shutdown is cancelled, the client is properly
# reset and can handle other commands normally.
$rd1 PING
assert_equal "PONG" [$rd1 read]

$rd1 close
$rd2 close

Expand Down
Loading