Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 16 additions & 22 deletions modules/cachedb_redis/cachedb_redis_dbase.c
Original file line number Diff line number Diff line change
Expand Up @@ -565,29 +565,24 @@ static int _redis_run_command(cachedb_con *connection, redisReply **rpl, str *ke
node->context->errstr);

if (match_prefix(reply->str, reply->len, MOVED_PREFIX, MOVED_PREFIX_LEN)) {
// It's a MOVED response
redis_moved *moved_info = pkg_malloc(sizeof(redis_moved));
if (!moved_info) {
LM_ERR("cachedb_redis: Unable to allocate redis_moved struct, no more pkg memory\n");
freeReplyObject(reply);
reply = NULL;
goto try_next_con;
} else {
if (parse_moved_reply(reply, moved_info) < 0) {
LM_ERR("cachedb_redis: Unable to parse MOVED reply\n");
pkg_free(moved_info);
moved_info = NULL;
freeReplyObject(reply);
goto try_next_con;
}

LM_DBG("cachedb_redis: MOVED slot: [%d] endpoint: [%.*s] port: [%d]\n", moved_info->slot, moved_info->endpoint.len, moved_info->endpoint.s, moved_info->port);
node = get_redis_connection_by_endpoint(con, moved_info);
/* MOVED response */
redis_moved moved_info_s;
redis_moved *moved_info = &moved_info_s;

pkg_free(moved_info);
moved_info = NULL;
if (parse_moved_reply(reply, moved_info) < 0) {
LM_ERR("failed to parse MOVED reply\n");
freeReplyObject(reply);
reply = NULL;
goto try_next_con;
}

LM_DBG("MOVED slot=%d endpoint=%.*s:%d\n",
moved_info->slot, moved_info->endpoint.len,
moved_info->endpoint.s, moved_info->port);
node = get_redis_connection_by_endpoint(con, moved_info);

freeReplyObject(reply);
reply = NULL;

if (node == NULL) {
LM_ERR("Unable to locate connection by endpoint\n");
Expand All @@ -603,9 +598,8 @@ static int _redis_run_command(cachedb_con *connection, redisReply **rpl, str *ke
}
}

i = QUERY_ATTEMPTS; // New node that is the target being MOVED to, should have the attempts reset
i = QUERY_ATTEMPTS;
continue;
}
}

freeReplyObject(reply);
Expand Down
4 changes: 3 additions & 1 deletion modules/cachedb_redis/cachedb_redis_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,7 @@ int parse_moved_reply(redisReply *reply, redis_moved *out) {
while (p < end && *p >= '0' && *p <= '9') {
slot = slot * 10 + (*p - '0');
p++;
if (slot > 16383) return ERR_INVALID_SLOT;
}
if (slot == 0 && (p == reply->str + MOVED_PREFIX_LEN || *(p - 1) < '0' || *(p - 1) > '9'))
return ERR_INVALID_SLOT;
Expand Down Expand Up @@ -426,11 +427,12 @@ int parse_moved_reply(redisReply *reply, redis_moved *out) {
while (p < end && *p >= '0' && *p <= '9') {
port = port * 10 + (*p - '0');
p++;
if (port > 65535) return ERR_INVALID_PORT;
}
if (port < 0 || port > 65535 || port_start == p)
return ERR_INVALID_PORT;
}
} else if (out->endpoint.s < end) {
} else if (p < end) {
out->endpoint.s = host_start;
out->endpoint.len = end - host_start;
}
Expand Down
Loading