Skip to content

Commit

Permalink
Assertion when sending SUBSCRIBE failed synchronously (#3985)
Browse files Browse the repository at this point in the history
* Handle possibility of reset buddy states after SUBSCRIBE send failure
  • Loading branch information
nanangizz authored Aug 13, 2024
1 parent f4f3f43 commit 0808be1
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions pjsip/src/pjsua-lib/pjsua_pres.c
Original file line number Diff line number Diff line change
Expand Up @@ -1995,6 +1995,7 @@ static void subscribe_buddy(pjsua_buddy_id buddy_id,
pjsip_tpselector tp_sel;
pj_status_t status;
const char *sub_str = presence? "presence": "dialog event";
pjsip_dialog *dlg;

/* Event subscription callback. */
pj_bzero(&pres_callback, sizeof(pres_callback));
Expand Down Expand Up @@ -2139,14 +2140,22 @@ static void subscribe_buddy(pjsua_buddy_id buddy_id,

pjsua_process_msg_data(tdata, NULL);

/* Send request. Note that if the send operation fails sync-ly, e.g:
* gethostbyname() error, tsx callback may have been invoked which may
* get the subscription terminated and the buddy states reset, we need
* to be prepared for such scenario here.
*/
dlg = buddy->dlg;

if (presence) {
status = pjsip_pres_send_request(buddy->sub, tdata);
} else {
status = pjsip_dlg_event_send_request(buddy->sub, tdata);
}
if (status != PJ_SUCCESS) {
pjsip_dlg_dec_lock(buddy->dlg);
pjsip_pres_terminate(buddy->sub, PJ_FALSE);
pjsip_dlg_dec_lock(dlg);
if (buddy->sub)
pjsip_pres_terminate(buddy->sub, PJ_FALSE);
buddy->sub = NULL;
pjsua_perror(THIS_FILE, "Unable to send initial SUBSCRIBE",
status);
Expand Down

0 comments on commit 0808be1

Please sign in to comment.