Skip to content

Commit

Permalink
cachedb_redis: Prevent crash when re-connect keeps failing
Browse files Browse the repository at this point in the history
(cherry picked from commit b501df7)
  • Loading branch information
khoegh authored and liviuchircu committed Apr 7, 2016
1 parent 87c93b8 commit 44d2748
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion modules/cachedb_redis/cachedb_redis_dbase.c
Expand Up @@ -111,7 +111,8 @@ int redis_reconnect_node(redis_con *con,cluster_node *node)
LM_DBG("reconnecting node %s:%d \n",node->ip,node->port);

/* close the old connection */
redisFree(node->context);
if(node->context)
redisFree(node->context);

return redis_connect_node(con,node);
}
Expand Down Expand Up @@ -254,6 +255,11 @@ void redis_destroy(cachedb_con *con) {
LM_ERR("Bad cluster configuration\n"); \
return -10; \
} \
if (node->context == NULL) { \
if (redis_reconnect_node(con,node) < 0) { \
return -1; \
} \
} \
for (i=2;i;i--) { \
reply = redisCommand(node->context,fmt,##args); \
if (reply == NULL || reply->type == REDIS_REPLY_ERROR) { \
Expand Down Expand Up @@ -616,6 +622,12 @@ int redis_raw_query_send(cachedb_con *connection,redisReply **reply,cdb_raw_entr
return -10;
}

if (node->context == NULL) {
if (redis_reconnect_node(con,node) < 0) {
return -1;
}
}

va_start(ap,attr);
end = attr->s[attr->len];
attr->s[attr->len] = 0;
Expand Down

0 comments on commit 44d2748

Please sign in to comment.