Skip to content

Commit

Permalink
Fixed race condition in ACK handling of INVITE message
Browse files Browse the repository at this point in the history
  • Loading branch information
sauwming committed Oct 31, 2023
1 parent 33f64ba commit 468cc27
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
17 changes: 12 additions & 5 deletions pjsip/src/pjsip-ua/sip_inv.c
Original file line number Diff line number Diff line change
Expand Up @@ -698,13 +698,20 @@ static pj_bool_t mod_inv_on_rx_request(pjsip_rx_data *rdata)
}

/* Now we can terminate the INVITE transaction */
pj_assert(inv->invite_tsx->status_code >= 200);
pjsip_tsx_terminate(inv->invite_tsx,
inv->invite_tsx->status_code);

/* In the case of an INVITE transaction, if the response was not
* 2xx, the ACK is considered part of the transaction, so
* should be handled by the transaction.
*/
if (inv->invite_tsx->status_code/100 == 2) {
pjsip_tsx_terminate(inv->invite_tsx,
inv->invite_tsx->status_code);
}
inv->invite_tsx = NULL;

if (inv->last_answer) {
pjsip_tx_data_dec_ref(inv->last_answer);
inv->last_answer = NULL;
pjsip_tx_data_dec_ref(inv->last_answer);
inv->last_answer = NULL;
}
}

Expand Down
12 changes: 12 additions & 0 deletions pjsip/src/pjsip/sip_transaction.c
Original file line number Diff line number Diff line change
Expand Up @@ -953,6 +953,18 @@ static pj_bool_t mod_tsx_layer_on_rx_request(pjsip_rx_data *rdata)
return PJ_FALSE;
}

/* In the case of an INVITE transaction, if the response was a 2xx,
* the ACK is not considered part of the transaction.
* Let sip_dialog and sip_inv handle it instead.
*/
if (rdata->msg_info.msg->line.req.method.id == PJSIP_ACK_METHOD &&
tsx->method.id == PJSIP_INVITE_METHOD &&
tsx->status_code/100 == 2)
{
pj_mutex_unlock( mod_tsx_layer.mutex);
return PJ_FALSE;
}

/* Prevent the transaction to get deleted before we have chance to lock it
* in pjsip_tsx_recv_msg().
*/
Expand Down

0 comments on commit 468cc27

Please sign in to comment.