Skip to content

Commit 87661e1

Browse files
committed
b2b_entities: avoid deadlock for certain scenarios
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
1 parent bf78309 commit 87661e1

File tree

1 file changed

+5
-5
lines changed
  • modules/b2b_entities

1 file changed

+5
-5
lines changed

modules/b2b_entities/dlg.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2666,6 +2666,7 @@ void b2b_tm_cback(struct cell *t, b2b_table htable, struct tmcb_params *ps)
26662666
int old_route_type;
26672667
bin_packet_t storage;
26682668
int b2b_ev = -1;
2669+
int lock_taken = 0;
26692670
struct b2b_context *ctx;
26702671
int b2b_cb_flags = 0;
26712672
unsigned int reqmask;
@@ -3402,19 +3403,18 @@ void b2b_tm_cback(struct cell *t, b2b_table htable, struct tmcb_params *ps)
34023403
b2b_route:
34033404

34043405
if (B2BE_SERIALIZE_STORAGE()) {
3406+
B2BE_LOCK_GET(htable, hash_index);
3407+
lock_taken = 1;
34053408
if (dlg_state == B2B_CONFIRMED && prev_state == B2B_MODIFIED) {
3406-
B2BE_LOCK_GET(htable, hash_index);
34073409

34083410
if (dlg->state != B2B_TERMINATED) {
34093411
b2b_ev = B2B_EVENT_UPDATE;
34103412
b2b_run_cb(dlg, hash_index, etype, B2BCB_TRIGGER_EVENT, b2b_ev,
34113413
&storage, serialize_backend);
34123414
} else {
34133415
b2b_ev = -1;
3414-
B2BE_LOCK_RELEASE(htable, hash_index);
34153416
}
34163417
} else if (b2b_ev == B2B_EVENT_CREATE) {
3417-
B2BE_LOCK_GET(htable, hash_index);
34183418

34193419
if (dlg->state != B2B_TERMINATED) {
34203420
b2b_run_cb(dlg, hash_index, etype, B2BCB_TRIGGER_EVENT, b2b_ev,
@@ -3424,7 +3424,6 @@ void b2b_tm_cback(struct cell *t, b2b_table htable, struct tmcb_params *ps)
34243424
b2be_db_insert(dlg, etype);
34253425
} else {
34263426
b2b_ev = -1;
3427-
B2BE_LOCK_RELEASE(htable, hash_index);
34283427
}
34293428
}
34303429
}
@@ -3449,8 +3448,9 @@ void b2b_tm_cback(struct cell *t, b2b_table htable, struct tmcb_params *ps)
34493448
if (b2be_db_update(dlg, etype) < 0)
34503449
LM_ERR("Failed to update in database\n");
34513450
B2BE_LOCK_RELEASE(htable, hash_index);
3452-
} else if (b2b_ev != -1)
3451+
} else if (lock_taken) {
34533452
B2BE_LOCK_RELEASE(htable, hash_index);
3453+
}
34543454

34553455
if (b2be_cluster) {
34563456
if (b2b_ev == B2B_EVENT_UPDATE)

0 commit comments

Comments
 (0)