From 784e1a4cc52be74c0a2e9706e74794c4ea5940cf Mon Sep 17 00:00:00 2001 From: Bogdan-Andrei Iancu Date: Mon, 23 Sep 2024 17:17:06 +0300 Subject: [PATCH] [clusterer] Fix error handling when failing to load nodes On failing to add a node (to the cluster), continue, as time as that node is not the current node. And if giving up on whole cluster info loading, be sure we clean up and properly report this to the above layer - the last thing we should do is to report success (on load) but have partial, unconsistent data. Fixes #3473 --- modules/clusterer/clusterer_mod.c | 2 +- modules/clusterer/node_info.c | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/modules/clusterer/clusterer_mod.c b/modules/clusterer/clusterer_mod.c index 0535d0188c9..34b9bbd2739 100644 --- a/modules/clusterer/clusterer_mod.c +++ b/modules/clusterer/clusterer_mod.c @@ -469,7 +469,7 @@ static int mod_init(void) LM_ERR("cannot initialize database connection\n"); goto error; } - if (load_db_info(&dr_dbf, db_hdl, &db_table, cluster_list) < 0) { + if (load_db_info(&dr_dbf, db_hdl, &db_table, cluster_list) != 0) { LM_ERR("Failed to load info from DB\n"); goto error; } diff --git a/modules/clusterer/node_info.c b/modules/clusterer/node_info.c index ea96ca6aba9..6f0baf96791 100644 --- a/modules/clusterer/node_info.c +++ b/modules/clusterer/node_info.c @@ -395,6 +395,7 @@ int load_db_info(db_func_t *dr_dbf, db_con_t* db_hdl, str *db_table, if (RES_ROW_N(res) == 0) { LM_WARN("Current node does not belong to any cluster\n"); + dr_dbf->free_result(db_hdl, res); return 1; } @@ -493,12 +494,17 @@ int load_db_info(db_func_t *dr_dbf, db_con_t* db_hdl, str *db_table, if ((rc = add_node_info(&_, cl_list, int_vals, str_vals)) != 0) { LM_ERR("Unable to add node info to backing list\n"); if (rc < 0) { - return -1; + /* serious error happened, better give up */ + goto error; } else if (int_vals[INT_VALS_NODE_ID_COL] == current_id) { LM_ERR("Invalid info for local node\n"); - return -1; + /* the node info is bogus, but cannot be skipped + * as it is the current node) */ + goto error; } else { - return 2; + /* the node info is bogus, just skip it + * (it's not current node) */ + continue; } } }