From 07a6b2e3e83d992d76ff611bfa485768ed209389 Mon Sep 17 00:00:00 2001 From: Vlad Patrascu Date: Sat, 25 Jun 2022 23:18:13 +0300 Subject: [PATCH] clusterer: make sure a discovered node is not added multiple times Do not insert a new node into the list multiple times when: * receiving multiple CLUSTERER_NODE_DESCRIPTION BIN messages * we receive a CLUSTERER_NODE_DESCRIPTION message and the node also appears in CLUSTERER_FULL_TOP_UPDATE messages. (cherry picked from commit b8e107517fd032f16f16df242a02474efc2312d2) --- modules/clusterer/node_info.c | 5 +++++ modules/clusterer/topology.c | 5 ----- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/modules/clusterer/node_info.c b/modules/clusterer/node_info.c index 355eb1bdc43..276d3645ebd 100644 --- a/modules/clusterer/node_info.c +++ b/modules/clusterer/node_info.c @@ -110,6 +110,11 @@ int add_node_info(node_info_t **new_info, cluster_info_t **cl_list, int *int_val *cl_list = cluster; } + if (get_node_by_id(cluster, int_vals[INT_VALS_NODE_ID_COL])) { + LM_DBG("Node [%d] already exists\n", int_vals[INT_VALS_NODE_ID_COL]); + return 0; + } + *new_info = shm_malloc(sizeof **new_info); if (!*new_info) { LM_ERR("no more shm memory\n"); diff --git a/modules/clusterer/topology.c b/modules/clusterer/topology.c index 9c16038a0c5..56cd826dbc7 100644 --- a/modules/clusterer/topology.c +++ b/modules/clusterer/topology.c @@ -698,11 +698,6 @@ static node_info_t *add_node(bin_packet_t *received, cluster_info_t *cl, lock_switch_read(cl_list_lock, lock_old_flag); return NULL; } - if (!new_node) { - LM_ERR("Unable to add node info to backing list\n"); - lock_switch_read(cl_list_lock, lock_old_flag); - return NULL; - } lock_switch_read(cl_list_lock, lock_old_flag);