Skip to content

Commit

Permalink
dialog: Fix shtag restoration when loading from DB
Browse files Browse the repository at this point in the history
This fixes a hanging dialog profiles bug on the backup box (NULL shtag),
in specific scenarios with dialogs + sharing tags, profiles with
value and dialog + profile replication clusters (whole enchilada).

In such cases, after restarting the backup box with active dialogs in
the DB, it would end up with forever-hanging dialog profiles in memory,
which would be continuously broadcasted to all cluster nodes,
effectively adding (doubling) unnecessary counters to the overall limit.

Credits to Vlad Pătrașcu for helping troubleshoot this bug!

(cherry picked from commit d77a9c5)
(cherry picked from commit ab1e5d4)
  • Loading branch information
liviuchircu committed Oct 27, 2022
1 parent 6059abe commit 86207d5
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions modules/dialog/dlg_db_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,13 @@ static int load_dialog_info_from_db(int dlg_hash_size)

dlg_unlock(d_table, d_entry);

if ((rc = fetch_dlg_value(dlg, &shtag_dlg_val, &tag_name, 0)) == 0) {
if (shm_str_dup(&dlg->shtag, &tag_name) < 0)
LM_ERR("No more shm memory\n");
} else if (rc == -1)
LM_ERR("Failed to get dlg value for sharing tag %.*s(%p)\n",
tag_name.len, tag_name.s, tag_name.s);

/* profiles */
if (!VAL_NULL(values+18))
read_dialog_profiles( VAL_STR(values+18).s,
Expand Down Expand Up @@ -774,12 +781,6 @@ static int load_dialog_info_from_db(int dlg_hash_size)
ref_dlg(dlg, 1);
}

if ((rc = fetch_dlg_value(dlg, &shtag_dlg_val, &tag_name, 0)) == 0) {
if (shm_str_dup(&dlg->shtag, &tag_name) < 0)
LM_ERR("No more shm memory\n");
} else if (rc == -1)
LM_ERR("Failed to get dlg value for sharing tag\n");

if (dlg_db_mode == DB_MODE_DELAYED) {
/* to be later removed by timer */
ref_dlg(dlg, 1);
Expand Down Expand Up @@ -1892,6 +1893,13 @@ static int sync_dlg_db_mem(void)
}
}

if ((rc = fetch_dlg_value(dlg, &shtag_dlg_val, &tag_name, 0)) == 0) {
if (shm_str_dup(&dlg->shtag, &tag_name) < 0)
LM_ERR("No more shm memory\n");
} else if (rc == -1)
LM_ERR("Failed to get dlg value for sharing tag %.*s(%p)\n",
tag_name.len, tag_name.s, tag_name.s);

/* profiles */
if (!VAL_NULL(values+18))
read_dialog_profiles( VAL_STR(values+18).s,
Expand Down Expand Up @@ -1972,12 +1980,6 @@ static int sync_dlg_db_mem(void)
}
}

if ((rc = fetch_dlg_value(dlg, &shtag_dlg_val, &tag_name, 0)) == 0) {
if (shm_str_dup(&dlg->shtag, &tag_name) < 0)
LM_ERR("No more shm memory\n");
} else if (rc == -1)
LM_ERR("Failed to get dlg value for sharing tag\n");

if (dlg_db_mode == DB_MODE_DELAYED) {
/* to be later removed by timer */
ref_dlg(dlg,1);
Expand Down

0 comments on commit 86207d5

Please sign in to comment.