Skip to content

Commit

Permalink
b2b_entities: avoid deadlock for certain scenarios
Browse files Browse the repository at this point in the history
When a call was terminted with a BYE from the handler of the 200 OK
reply, the entities lock would remain locked, generating a deadlock.
This commit fixes this (and possible other) situations by generically
keeping a track when the lock is taken and unlock it before exiting.

Thanks to Vlad Patrascu for helping with debugging and solution for this

(cherry picked from commit 87661e1)
  • Loading branch information
razvancrainea authored and rvlad-patrascu committed Feb 21, 2023
1 parent e0b4585 commit acb6877
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions modules/b2b_entities/dlg.c
Original file line number Diff line number Diff line change
Expand Up @@ -2568,6 +2568,7 @@ void b2b_tm_cback(struct cell *t, b2b_table htable, struct tmcb_params *ps)
int old_route_type;
bin_packet_t storage;
int b2b_ev = -1;
int lock_taken = 0;
struct b2b_context *ctx;
int b2b_cb_flags = 0;
unsigned int reqmask;
Expand Down Expand Up @@ -3284,18 +3285,16 @@ void b2b_tm_cback(struct cell *t, b2b_table htable, struct tmcb_params *ps)
b2b_route:

if (B2BE_SERIALIZE_STORAGE()) {
lock_get(&htable[hash_index].lock);
lock_taken = 1;
if (dlg_state == B2B_CONFIRMED && prev_state == B2B_MODIFIED) {
lock_get(&htable[hash_index].lock);

if (dlg->state != B2B_TERMINATED) {
b2b_ev = B2B_EVENT_UPDATE;
b2b_run_cb(dlg, hash_index, etype, B2BCB_TRIGGER_EVENT, b2b_ev,
&storage, serialize_backend);
} else
b2b_ev = -1;
} else if (b2b_ev == B2B_EVENT_CREATE) {
lock_get(&htable[hash_index].lock);

if (dlg->state != B2B_TERMINATED) {
b2b_run_cb(dlg, hash_index, etype, B2BCB_TRIGGER_EVENT, b2b_ev,
&storage, serialize_backend);
Expand Down Expand Up @@ -3327,8 +3326,9 @@ void b2b_tm_cback(struct cell *t, b2b_table htable, struct tmcb_params *ps)
if (b2be_db_update(dlg, etype) < 0)
LM_ERR("Failed to update in database\n");
lock_release(&htable[hash_index].lock);
} else if (b2b_ev != -1)
} else if (lock_taken) {
lock_release(&htable[hash_index].lock);
}

if (b2be_cluster) {
if (b2b_ev == B2B_EVENT_UPDATE)
Expand Down

0 comments on commit acb6877

Please sign in to comment.