Skip to content

Commit

Permalink
replication: fix io-threads possible race by moving waitForClientIO e…
Browse files Browse the repository at this point in the history
…arlier

Signed-off-by: Uri Yagelnik <[email protected]>
  • Loading branch information
uriyage committed Dec 11, 2024
1 parent 789a73b commit bbc1829
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/replication.c
Original file line number Diff line number Diff line change
Expand Up @@ -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")) {
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit bbc1829

Please sign in to comment.