From e0e9e2f943ca5bd35f653f6e55a89000e8b262e6 Mon Sep 17 00:00:00 2001 From: Vlad Patrascu Date: Thu, 14 Jul 2022 12:52:37 +0300 Subject: [PATCH] clusterer: fix possible deadlocks when discovering a new node Use only standard RW locking operations for the global list lock instead of the "switchable" mechanism (aquiring the lock for writing when necessary). --- modules/clusterer/clusterer.c | 11 ++++------- modules/clusterer/topology.c | 6 ------ 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/modules/clusterer/clusterer.c b/modules/clusterer/clusterer.c index 1610349aca2..e461370b346 100644 --- a/modules/clusterer/clusterer.c +++ b/modules/clusterer/clusterer.c @@ -958,7 +958,6 @@ static void handle_cl_mi_msg(bin_packet_t *packet) static void handle_remove_node(bin_packet_t *packet, cluster_info_t *cl) { int target_node; - int lock_old_flag; node_info_t *node; int ev_actions_cl = 1; @@ -995,9 +994,7 @@ static void handle_remove_node(bin_packet_t *packet, cluster_info_t *cl) return; } - lock_switch_write(cl_list_lock, lock_old_flag); remove_node(cl, node); - lock_switch_read(cl_list_lock, lock_old_flag); } void bin_rcv_cl_extra_packets(bin_packet_t *packet, int packet_type, @@ -1024,7 +1021,7 @@ void bin_rcv_cl_extra_packets(bin_packet_t *packet, int packet_type, } if (!db_mode && packet_type == CLUSTERER_REMOVE_NODE) - lock_start_sw_read(cl_list_lock); + lock_start_write(cl_list_lock); else lock_start_read(cl_list_lock); @@ -1119,7 +1116,7 @@ void bin_rcv_cl_extra_packets(bin_packet_t *packet, int packet_type, exit: if (!db_mode && packet_type == CLUSTERER_REMOVE_NODE) - lock_stop_sw_read(cl_list_lock); + lock_stop_write(cl_list_lock); else lock_stop_read(cl_list_lock); } @@ -1151,7 +1148,7 @@ void bin_rcv_cl_packets(bin_packet_t *packet, int packet_type, if (!db_mode && (packet_type == CLUSTERER_NODE_DESCRIPTION || packet_type == CLUSTERER_FULL_TOP_UPDATE)) - lock_start_sw_read(cl_list_lock); + lock_start_write(cl_list_lock); else lock_start_read(cl_list_lock); @@ -1199,7 +1196,7 @@ void bin_rcv_cl_packets(bin_packet_t *packet, int packet_type, exit: if (!db_mode && (packet_type == CLUSTERER_NODE_DESCRIPTION || packet_type == CLUSTERER_FULL_TOP_UPDATE)) - lock_stop_sw_read(cl_list_lock); + lock_stop_write(cl_list_lock); else lock_stop_read(cl_list_lock); } diff --git a/modules/clusterer/topology.c b/modules/clusterer/topology.c index 7c443662355..e5fe1e94d44 100644 --- a/modules/clusterer/topology.c +++ b/modules/clusterer/topology.c @@ -682,7 +682,6 @@ static node_info_t *add_node(bin_packet_t *received, cluster_info_t *cl, int src_node_id, str *str_vals, int *int_vals) { node_info_t *new_node = NULL; - int lock_old_flag; str_vals[STR_VALS_FLAGS_COL].s = 0; str_vals[STR_VALS_DESCRIPTION_COL].s = 0; @@ -691,16 +690,11 @@ static node_info_t *add_node(bin_packet_t *received, cluster_info_t *cl, int_vals[INT_VALS_NODE_ID_COL] = src_node_id; int_vals[INT_VALS_STATE_COL] = 1; /* enabled */ - lock_switch_write(cl_list_lock, lock_old_flag); - if (add_node_info(&new_node, &cl, int_vals, str_vals) != 0) { 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); - return new_node; }