Make the connect timeout configurable when in cluster mode to prevent huge delays

This commit is contained in:
John Sully 2023-10-12 15:43:19 +00:00 committed by John Sully
parent dfcc848e1c
commit cd42776c9f

View File

@ -2524,7 +2524,10 @@ cleanup:
static int clusterManagerNodeConnect(clusterManagerNode *node) { static int clusterManagerNodeConnect(clusterManagerNode *node) {
if (node->context) redisFree(node->context); if (node->context) redisFree(node->context);
node->context = redisConnect(node->ip, node->port); struct timeval tv;
tv.tv_sec = config.cluster_manager_command.timeout / 1000;
tv.tv_usec = (config.cluster_manager_command.timeout % 1000) * 1000;
node->context = redisConnectWithTimeout(node->ip, node->port, tv);
if (!node->context->err && config.tls) { if (!node->context->err && config.tls) {
const char *err = NULL; const char *err = NULL;
if (cliSecureConnection(node->context, config.sslconfig, &err) == REDIS_ERR && err) { if (cliSecureConnection(node->context, config.sslconfig, &err) == REDIS_ERR && err) {
@ -5626,7 +5629,10 @@ static int clusterManagerCommandImport(int argc, char **argv) {
char *reply_err = NULL; char *reply_err = NULL;
redisReply *src_reply = NULL; redisReply *src_reply = NULL;
// Connect to the source node. // Connect to the source node.
redisContext *src_ctx = redisConnect(src_ip, src_port); struct timeval tv;
tv.tv_sec = config.cluster_manager_command.timeout / 1000;
tv.tv_usec = (config.cluster_manager_command.timeout % 1000) * 1000;
redisContext *src_ctx = redisConnectWithTimeout(src_ip, src_port, tv);
if (src_ctx->err) { if (src_ctx->err) {
success = 0; success = 0;
fprintf(stderr,"Could not connect to KeyDB at %s:%d: %s.\n", src_ip, fprintf(stderr,"Could not connect to KeyDB at %s:%d: %s.\n", src_ip,