From eb7f31e7affdaebd5eb0c829f36d1007ec4794fd Mon Sep 17 00:00:00 2001 From: Jozsef Koszo Date: Sun, 17 Mar 2024 07:44:49 +0100 Subject: [PATCH] Fix random connection timeouts with Redis Cluster When a node timeout occurs, then phpredis will try to connect to another node, whose answer probably will be MOVED redirect. After this we need more time to accomplish the redirection, otherwise we get "Timed out attempting to find data in the correct node" error message. Fixes #795 #888 #1142 #1385 #1633 #1707 #1811 #2407 --- cluster_library.c | 2 +- redis_cluster.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cluster_library.c b/cluster_library.c index 9258fca..3bd4fc7 100644 --- a/cluster_library.c +++ b/cluster_library.c @@ -833,7 +833,7 @@ PHP_REDIS_API redisCluster *cluster_create(double timeout, double read_timeout, c->err = NULL; /* Set up our waitms based on timeout */ - c->waitms = (long)(1000 * timeout); + c->waitms = (long)(1000 * (timeout + read_timeout)); /* Allocate our seeds hash table */ ALLOC_HASHTABLE(c->seeds); diff --git a/redis_cluster.c b/redis_cluster.c index 599449a..77d0106 100644 --- a/redis_cluster.c +++ b/redis_cluster.c @@ -139,7 +139,7 @@ static void redis_cluster_init(redisCluster *c, HashTable *ht_seeds, double time c->flags->timeout = timeout; c->flags->read_timeout = read_timeout; c->flags->persistent = persistent; - c->waitms = timeout * 1000L; + c->waitms = (long)(1000 * (timeout + read_timeout)); /* Attempt to load slots from cache if caching is enabled */ if (CLUSTER_CACHING_ENABLED()) {