diff --git a/src/blocked.c b/src/blocked.c index 5ec29eb00..b9df8aa02 100644 --- a/src/blocked.c +++ b/src/blocked.c @@ -270,6 +270,7 @@ void disconnectAllBlockedClients(void) { if (c->bstate.btype == BLOCKED_LAZYFREE) { addReply(c, shared.ok); /* No reason lazy-free to fail */ + updateStatsOnUnblock(c, 0, 0, 0); c->flags &= ~CLIENT_PENDING_COMMAND; unblockClient(c, 1); } else { diff --git a/src/db.c b/src/db.c index cc35f171d..609e27c85 100644 --- a/src/db.c +++ b/src/db.c @@ -702,7 +702,7 @@ void flushallSyncBgDone(uint64_t client_id) { client *c = lookupClientByID(client_id); /* Verify that client still exists */ - if (!c) return; + if (!(c && c->flags & CLIENT_BLOCKED)) return; /* Update current_client (Called functions might rely on it) */ client *old_client = server.current_client; diff --git a/tests/unit/lazyfree.tcl b/tests/unit/lazyfree.tcl index b4ade4031..b4650a500 100644 --- a/tests/unit/lazyfree.tcl +++ b/tests/unit/lazyfree.tcl @@ -174,4 +174,18 @@ start_server {tags {"lazyfree"}} { assert_equal [s lazyfreed_objects] 2 $rd close } + + test "Unblocks client blocked on lazyfree via REPLICAOF command" { + set rd [redis_deferring_client] + + populate 50000 ;# Just to make flushdb async slower + $rd flushdb + wait_for_blocked_client + # Test that slaveof command unblocks clients without assertion failure + r slaveof 127.0.0.1 0 + assert_equal [$rd read] {OK} + $rd close + r ping + r slaveof no one + } {OK} {external:skip} }