Skip to content

Commit

Permalink
tm: check branches that should be cancelled under lock
Browse files Browse the repository at this point in the history
This fix avoids race condition between a CANCEL message and replies that
are coming in the same time.

Thanks go to Tommy Brecher for reprting this and offering extensive logs
to debug the issue in ticket #1759.
Credits for the fix are shared with Bogdan Iancu for the brainstoring.

(cherry picked from commit 6e39385)
  • Loading branch information
razvancrainea committed Jul 18, 2019
1 parent 9bbf35b commit 5533417
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions modules/tm/t_cancel.c
Expand Up @@ -95,6 +95,7 @@ void cancel_branch( struct cell *t, int branch )
}
# endif


cancel=build_cancel(t, branch, &len);
if (!cancel) {
LM_ERR("attempt to build a CANCEL failed\n");
Expand Down
4 changes: 4 additions & 0 deletions modules/tm/t_fwd.c
Expand Up @@ -621,8 +621,12 @@ void cancel_invite(struct sip_msg *cancel_msg,

get_cancel_reason(cancel_msg, t_cancel->flags, &reason);

LOCK_REPLIES(t_invite);
/* we need to check which branches should be canceled under lock to avoid
* concurrency with replies that are coming in the same time */
/* generate local cancels for all branches */
which_cancel(t_invite, &cancel_bitmap );
UNLOCK_REPLIES(t_invite);

set_cancel_extra_hdrs( reason.s, reason.len);
cancel_uacs(t_invite, cancel_bitmap );
Expand Down

0 comments on commit 5533417

Please sign in to comment.