summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2014-09-17 16:39:41 +0200
committerantirez <antirez@gmail.com>2014-09-19 14:22:00 +0200
commit015cbf3015f53836b86258b1525872d6eb99402f (patch)
tree89c75b202571e33d5a00c78b131129fdd4d9b6fc
parentd4c3c1248f72f53fe9c52826d0a6bc92ec4d85fb (diff)
downloadredis-015cbf3015f53836b86258b1525872d6eb99402f.tar.gz
Cluster: claim ping_sent time even if we can't connect.
This fixes a potential bug that was never observed in practice since what happens is that the asynchronous connect returns ok (to fail later, calling the handler) every time, so a ping is queued, and sent_ping happens to always be populated. Howver technically connect(2) with a non blocking socket may return an error synchronously, so before this fix the code was not correct.
-rw-r--r--src/cluster.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/cluster.c b/src/cluster.c
index 7f9047a94..821fe1734 100644
--- a/src/cluster.c
+++ b/src/cluster.c
@@ -2825,6 +2825,12 @@ void clusterCron(void) {
fd = anetTcpNonBlockBindConnect(server.neterr, node->ip,
node->port+REDIS_CLUSTER_PORT_INCR, REDIS_BIND_ADDR);
if (fd == -1) {
+ /* We got a synchronous error from connect before
+ * clusterSendPing() had a chance to be called.
+ * If node->ping_sent is zero, failure detection can't work,
+ * so we claim we actually sent a ping now (that will
+ * be really sent as soon as the link is obtained). */
+ if (node->ping_sent == 0) node->ping_sent = mstime();
redisLog(REDIS_DEBUG, "Unable to connect to "
"Cluster Node [%s]:%d -> %s", node->ip,
node->port+REDIS_CLUSTER_PORT_INCR,