Skip to content

Commit

Permalink
clusterer: fix possible deadlocks when discovering a new node
Browse files Browse the repository at this point in the history
Use only standard RW locking operations for the global list lock instead of
the "switchable" mechanism (aquiring the lock for writing when necessary).
  • Loading branch information
rvlad-patrascu committed Jul 14, 2022
1 parent 4ab5c63 commit e0e9e2f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 13 deletions.
11 changes: 4 additions & 7 deletions modules/clusterer/clusterer.c
Expand Up @@ -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;

Expand Down Expand Up @@ -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,
Expand All @@ -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);

Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);
}
Expand Down
6 changes: 0 additions & 6 deletions modules/clusterer/topology.c
Expand Up @@ -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;
Expand All @@ -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;
}

Expand Down

0 comments on commit e0e9e2f

Please sign in to comment.