From 2374496799fc4d75338f821fa377a211f9557a55 Mon Sep 17 00:00:00 2001 From: antirez Date: Wed, 17 Sep 2014 16:39:41 +0200 Subject: [PATCH] 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. --- src/cluster.c | 6 ++++++ 1 file changed, 6 insertions(+) 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,