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.
This commit is contained in:
antirez 2014-09-17 16:39:41 +02:00
parent c89afc8e5d
commit 2374496799

View File

@ -2825,6 +2825,12 @@ void clusterCron(void) {
fd = anetTcpNonBlockBindConnect(server.neterr, node->ip, fd = anetTcpNonBlockBindConnect(server.neterr, node->ip,
node->port+REDIS_CLUSTER_PORT_INCR, REDIS_BIND_ADDR); node->port+REDIS_CLUSTER_PORT_INCR, REDIS_BIND_ADDR);
if (fd == -1) { 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 " redisLog(REDIS_DEBUG, "Unable to connect to "
"Cluster Node [%s]:%d -> %s", node->ip, "Cluster Node [%s]:%d -> %s", node->ip,
node->port+REDIS_CLUSTER_PORT_INCR, node->port+REDIS_CLUSTER_PORT_INCR,