summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2013-10-04 16:12:25 +0200
committerantirez <antirez@gmail.com>2013-10-04 16:14:57 +0200
commitdf0c96002d76e52093045416636415ba2e39a346 (patch)
tree7e20f83f3590771868670d05c82aa46ea273ff14
parentd7fa6d9aba0bb765d299171c796aeff754261e08 (diff)
downloadredis-df0c96002d76e52093045416636415ba2e39a346.tar.gz
Replication: install the write handler when reusing a cached master.
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.
-rw-r--r--src/replication.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/replication.c b/src/replication.c
index 2652b2933..c0018cec8 100644
--- a/src/replication.c
+++ b/src/replication.c
@@ -1347,6 +1347,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 --------------------------- */