Skip to content

Commit

Permalink
Replication: install the write handler when reusing a cached master.
Browse files Browse the repository at this point in the history
Sometimes when we resurrect a cached master after a successful partial
resynchronization attempt, there is pending data in the output buffers
of the client structure representing the master (likely REPLCONF ACK
commands).

If we don't reinstall the write handler, it will never be installed
again by addReply*() family functions as they'll assume that if there is
already data pending, the write handler is already installed.

This bug caused some slaves after a successful partial sync to never
send REPLCONF ACK, and continuously being detected as timing out by the
master, with a disconnection / reconnection loop.
  • Loading branch information
antirez committed Oct 4, 2013
1 parent b41570f commit 1461422
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/replication.c
Original file line number Diff line number Diff line change
Expand Up @@ -1375,6 +1375,16 @@ void replicationResurrectCachedMaster(int newfd) {
redisLog(REDIS_WARNING,"Error resurrecting the cached master, impossible to add the readable handler: %s", strerror(errno));
freeClientAsync(server.master); /* Close ASAP. */
}

/* We may also need to install the write handler as well if there is
* pending data in the write buffers. */
if (server.master->bufpos || listLength(server.master->reply)) {
if (aeCreateFileEvent(server.el, newfd, AE_WRITABLE,
sendReplyToClient, server.master)) {
redisLog(REDIS_WARNING,"Error resurrecting the cached master, impossible to add the writable handler: %s", strerror(errno));
freeClientAsync(server.master); /* Close ASAP. */
}
}
}

/* ------------------------- MIN-SLAVES-TO-WRITE --------------------------- */
Expand Down

0 comments on commit 1461422

Please sign in to comment.