res_pjsip_session.c: Process initial INVITE sooner. (key exists)

Retransmissions of an initial INVITE could be queued in the serializer
before we have processed the first INVITE message.  If the first INVITE
message doesn't get completely processed before the retransmissions are
seen then we could try to setup the same call from the retransmissions.  A
symptom of this is seeing a (key exists) message associated with an
INVITE.  An earlier change attempted to address this kind of problem by
calculating a distributor serializer to use for unassociated messages.
Part of that change also made incoming calls keep using that distributor
serializer.  (ASTERISK-26088) However, some leftover code was still
deferring the INVITE processing to the session's serializer even though we
were already in that serializer.  This not only is unnecessary but would
cause the same call resetup problem.

* Removed the code to defer processing the initial INVITE to the session's
serializer because we are already running in that serializer.

ASTERISK-26998 #close

Change-Id: I1e822d82dcc650e508bc2d40d545d5de4f3421f6
This commit is contained in:
Richard Mudgett
2017-05-12 21:04:59 -05:00
parent 094093b31d
commit 30fbed65f1

View File

@@ -2096,39 +2096,8 @@ struct new_invite {
pjsip_rx_data *rdata; pjsip_rx_data *rdata;
}; };
static void new_invite_destroy(void *obj) static int new_invite(struct new_invite *invite)
{ {
struct new_invite *invite = obj;
ao2_cleanup(invite->session);
if (invite->rdata) {
pjsip_rx_data_free_cloned(invite->rdata);
}
}
static struct new_invite *new_invite_alloc(struct ast_sip_session *session, pjsip_rx_data *rdata)
{
struct new_invite *invite = ao2_alloc(sizeof(*invite), new_invite_destroy);
if (!invite) {
return NULL;
}
ao2_ref(session, +1);
invite->session = session;
if (pjsip_rx_data_clone(rdata, 0, &invite->rdata) != PJ_SUCCESS) {
ao2_ref(invite, -1);
return NULL;
}
return invite;
}
static int new_invite(void *data)
{
RAII_VAR(struct new_invite *, invite, data, ao2_cleanup);
pjsip_tx_data *tdata = NULL; pjsip_tx_data *tdata = NULL;
pjsip_timer_setting timer; pjsip_timer_setting timer;
pjsip_rdata_sdp_info *sdp_info; pjsip_rdata_sdp_info *sdp_info;
@@ -2250,7 +2219,7 @@ static void handle_new_invite_request(pjsip_rx_data *rdata)
pjsip_tx_data *tdata = NULL; pjsip_tx_data *tdata = NULL;
pjsip_inv_session *inv_session = NULL; pjsip_inv_session *inv_session = NULL;
struct ast_sip_session *session; struct ast_sip_session *session;
struct new_invite *invite; struct new_invite invite;
ast_assert(endpoint != NULL); ast_assert(endpoint != NULL);
@@ -2287,18 +2256,17 @@ static void handle_new_invite_request(pjsip_rx_data *rdata)
return; return;
} }
invite = new_invite_alloc(session, rdata); /*
if (!invite || ast_sip_push_task(session->serializer, new_invite, invite)) { * The current thread is supposed be the session serializer to prevent
if (pjsip_inv_initial_answer(inv_session, rdata, 500, NULL, NULL, &tdata) == PJ_SUCCESS) { * any initial INVITE retransmissions from trying to setup the same
pjsip_inv_terminate(inv_session, 500, PJ_FALSE); * call again.
} else { */
pjsip_inv_send_msg(inv_session, tdata); ast_assert(ast_taskprocessor_is_task(session->serializer));
}
#ifdef HAVE_PJSIP_INV_SESSION_REF invite.session = session;
pjsip_inv_dec_ref(inv_session); invite.rdata = rdata;
#endif new_invite(&invite);
ao2_cleanup(invite);
}
ao2_ref(session, -1); ao2_ref(session, -1);
} }
@@ -2339,13 +2307,14 @@ static pj_bool_t has_supplement(const struct ast_sip_session *session, const pjs
* 2) An in-dialog request that the inv_session layer does not * 2) An in-dialog request that the inv_session layer does not
* handle is received (such as an in-dialog INFO) * handle is received (such as an in-dialog INFO)
* *
* In all cases, there is very little we actually do in this function * Except for INVITEs, there is very little we actually do in this function
* 1) For requests we don't handle, we return PJ_FALSE * 1) For requests we don't handle, we return PJ_FALSE
* 2) For new INVITEs, throw the work into the SIP threadpool to be done * 2) For new INVITEs, handle them now to prevent retransmissions from
* there to free up the thread(s) handling incoming requests * trying to setup the same call again.
* 3) For in-dialog requests we handle, we defer handling them until the * 3) For in-dialog requests we handle, we process them in the
* on_inv_state_change() callback instead (where we will end up putting * .on_state_changed = session_inv_on_state_changed or
* them into the threadpool). * .on_tsx_state_changed = session_inv_on_tsx_state_changed
* callbacks instead.
*/ */
static pj_bool_t session_on_rx_request(pjsip_rx_data *rdata) static pj_bool_t session_on_rx_request(pjsip_rx_data *rdata)
{ {