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
  • Loading branch information
razvancrainea committed Nov 16, 2022
1 parent bf78309 commit 87661e1
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 @@ -2666,6 +2666,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 @@ -3402,19 +3403,18 @@ void b2b_tm_cback(struct cell *t, b2b_table htable, struct tmcb_params *ps)
b2b_route:

if (B2BE_SERIALIZE_STORAGE()) {
B2BE_LOCK_GET(htable, hash_index);
lock_taken = 1;
if (dlg_state == B2B_CONFIRMED && prev_state == B2B_MODIFIED) {
B2BE_LOCK_GET(htable, hash_index);

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;
B2BE_LOCK_RELEASE(htable, hash_index);
}
} else if (b2b_ev == B2B_EVENT_CREATE) {
B2BE_LOCK_GET(htable, hash_index);

if (dlg->state != B2B_TERMINATED) {
b2b_run_cb(dlg, hash_index, etype, B2BCB_TRIGGER_EVENT, b2b_ev,
Expand All @@ -3424,7 +3424,6 @@ void b2b_tm_cback(struct cell *t, b2b_table htable, struct tmcb_params *ps)
b2be_db_insert(dlg, etype);
} else {
b2b_ev = -1;
B2BE_LOCK_RELEASE(htable, hash_index);
}
}
}
Expand All @@ -3449,8 +3448,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");
B2BE_LOCK_RELEASE(htable, hash_index);
} else if (b2b_ev != -1)
} else if (lock_taken) {
B2BE_LOCK_RELEASE(htable, hash_index);
}

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

0 comments on commit 87661e1

Please sign in to comment.