From 930267a902d25dbce8ff63b6a1fc190833d63b4b Mon Sep 17 00:00:00 2001 From: Uri Yagelnik Date: Wed, 11 Dec 2024 07:57:24 +0000 Subject: [PATCH] replication: fix io-threads possible race by moving waitForClientIO earlier --- src/replication.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/replication.c b/src/replication.c index 8ff8ad3f0f..22a710c291 100644 --- a/src/replication.c +++ b/src/replication.c @@ -1036,6 +1036,9 @@ void syncCommand(client *c) { /* ignore SYNC if already replica or in monitor mode */ if (c->flag.replica) return; + /* Wait for any IO pending operation to finish before changing the client state to replica */ + waitForClientIO(c); + /* Check if this is a failover request to a replica with the same replid and * become a primary if so. */ if (c->argc > 3 && !strcasecmp(c->argv[0]->ptr, "psync") && !strcasecmp(c->argv[3]->ptr, "failover")) { @@ -1147,8 +1150,6 @@ void syncCommand(client *c) { c->repl_state = REPLICA_STATE_WAIT_BGSAVE_START; if (server.repl_disable_tcp_nodelay) connDisableTcpNoDelay(c->conn); /* Non critical if it fails. */ c->repldbfd = -1; - /* Wait for any IO pending operation to finish before changing the client state */ - waitForClientIO(c); c->flag.replica = 1; listAddNodeTail(server.replicas, c);