Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash when freeing newly created node when nodeIp2String fail #1535

Merged
merged 3 commits into from
Jan 10, 2025
Merged
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
20 changes: 12 additions & 8 deletions src/cluster_legacy.c
Original file line number Diff line number Diff line change
Expand Up @@ -3245,6 +3245,17 @@ int clusterProcessPacket(clusterLink *link) {
if (type == CLUSTERMSG_TYPE_MEET) {
if (!sender) {
if (!link->node) {
char ip[NET_IP_STR_LEN] = {0};
if (nodeIp2String(ip, link, hdr->myip) != C_OK) {
/* Unable to retrieve the node's IP address from the connection. Without a
* valid IP, the node becomes unusable in the cluster. This failure might be
* due to the connection being closed. */
serverLog(LL_NOTICE, "Closing link even though we received a MEET packet on it, "
"because the connection has an error");
freeClusterLink(link);
return 0;
}

/* Add this node if it is new for us and the msg type is MEET.
* In this stage we don't try to add the node with the right
* flags, replicaof pointer, and so forth, as this details will be
Expand All @@ -3253,14 +3264,7 @@ int clusterProcessPacket(clusterLink *link) {
* we want to send extensions right away in the return PONG in order
* to reduce the amount of time needed to stabilize the shard ID. */
clusterNode *node = createClusterNode(NULL, CLUSTER_NODE_HANDSHAKE);
if (nodeIp2String(node->ip, link, hdr->myip) != C_OK) {
/* We cannot get the IP info from the link, it probably means the connection is closed. */
serverLog(LL_NOTICE, "Closing link even though we received a MEET packet on it, "
"because the connection has an error");
freeClusterLink(link);
freeClusterNode(node);
return 0;
}
memcpy(node->ip, ip, sizeof(ip));
getClientPortFromClusterMsg(hdr, &node->tls_port, &node->tcp_port);
node->cport = ntohs(hdr->cport);
if (hdr->mflags[0] & CLUSTERMSG_FLAG0_EXT_DATA) {
Expand Down
Loading