diff --git a/src/cluster_legacy.c b/src/cluster_legacy.c index 0777d6d8c6..bf5d314908 100644 --- a/src/cluster_legacy.c +++ b/src/cluster_legacy.c @@ -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 @@ -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) {