Skip to content

Commit cd42776

Browse files
JohnSullyJohn Sully
authored andcommitted
Make the connect timeout configurable when in cluster mode to prevent huge delays
1 parent dfcc848 commit cd42776

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

src/redis-cli.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2524,7 +2524,10 @@ static int clusterManagerExecTransaction(clusterManagerNode *node,
25242524

25252525
static int clusterManagerNodeConnect(clusterManagerNode *node) {
25262526
if (node->context) redisFree(node->context);
2527-
node->context = redisConnect(node->ip, node->port);
2527+
struct timeval tv;
2528+
tv.tv_sec = config.cluster_manager_command.timeout / 1000;
2529+
tv.tv_usec = (config.cluster_manager_command.timeout % 1000) * 1000;
2530+
node->context = redisConnectWithTimeout(node->ip, node->port, tv);
25282531
if (!node->context->err && config.tls) {
25292532
const char *err = NULL;
25302533
if (cliSecureConnection(node->context, config.sslconfig, &err) == REDIS_ERR && err) {
@@ -5626,7 +5629,10 @@ static int clusterManagerCommandImport(int argc, char **argv) {
56265629
char *reply_err = NULL;
56275630
redisReply *src_reply = NULL;
56285631
// Connect to the source node.
5629-
redisContext *src_ctx = redisConnect(src_ip, src_port);
5632+
struct timeval tv;
5633+
tv.tv_sec = config.cluster_manager_command.timeout / 1000;
5634+
tv.tv_usec = (config.cluster_manager_command.timeout % 1000) * 1000;
5635+
redisContext *src_ctx = redisConnectWithTimeout(src_ip, src_port, tv);
56305636
if (src_ctx->err) {
56315637
success = 0;
56325638
fprintf(stderr,"Could not connect to KeyDB at %s:%d: %s.\n", src_ip,

0 commit comments

Comments
 (0)