Skip to content

Commit 930267a

Browse files
committed
replication: fix io-threads possible race by moving waitForClientIO earlier
1 parent 789a73b commit 930267a

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/replication.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,6 +1036,9 @@ void syncCommand(client *c) {
10361036
/* ignore SYNC if already replica or in monitor mode */
10371037
if (c->flag.replica) return;
10381038

1039+
/* Wait for any IO pending operation to finish before changing the client state to replica */
1040+
waitForClientIO(c);
1041+
10391042
/* Check if this is a failover request to a replica with the same replid and
10401043
* become a primary if so. */
10411044
if (c->argc > 3 && !strcasecmp(c->argv[0]->ptr, "psync") && !strcasecmp(c->argv[3]->ptr, "failover")) {
@@ -1147,8 +1150,6 @@ void syncCommand(client *c) {
11471150
c->repl_state = REPLICA_STATE_WAIT_BGSAVE_START;
11481151
if (server.repl_disable_tcp_nodelay) connDisableTcpNoDelay(c->conn); /* Non critical if it fails. */
11491152
c->repldbfd = -1;
1150-
/* Wait for any IO pending operation to finish before changing the client state */
1151-
waitForClientIO(c);
11521153
c->flag.replica = 1;
11531154
listAddNodeTail(server.replicas, c);
11541155

0 commit comments

Comments
 (0)