diff --git a/src/db.c b/src/db.c index cf31df4e1..63b561d84 100644 --- a/src/db.c +++ b/src/db.c @@ -834,8 +834,13 @@ void flushallSyncBgDone(uint64_t client_id, void *sflush) { /* mark client as unblocked */ unblockClient(c, 1); - /* FLUSH command is finished. resetClient() and update replication offset. */ - commandProcessed(c); + if (c->flags & CLIENT_PENDING_COMMAND) { + c->flags &= ~CLIENT_PENDING_COMMAND; + /* The FLUSH command won't be reprocessed, FLUSH command is finished, but + * we still need to complete its full processing flow, including updating + * the replication offset. */ + commandProcessed(c); + } /* On flush completion, update the client's memory */ updateClientMemUsageAndBucket(c); @@ -880,6 +885,10 @@ int flushCommandCommon(client *c, int type, int flags, SlotsFlush *sflush) { elapsedStart(&c->bstate.lazyfreeStartTime); c->bstate.timeout = 0; + /* We still need to perform cleanup operations for the command, including + * updating the replication offset, so mark this command as pending to + * avoid command from being reset during unblock. */ + c->flags |= CLIENT_PENDING_COMMAND; blockClient(c,BLOCKED_LAZYFREE); bioCreateCompRq(BIO_WORKER_LAZY_FREE, flushallSyncBgDone, c->id, sflush); }