<p>Joshua Colp has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/13736">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">res_pjsip_session: Fix off-nominal session refresh.<br><br>Given a scenario where session refreshes occur close to<br>each other while another is finishing it was possible for<br>the session refreshes to occur out of order.<br><br>For the out of order session refreshes the first session<br>refresh would be queued due to a transaction in progress.<br>This transaction would then finish. When finished a<br>separate task to process the delayed requests queue<br>would be queued for handling. A second refresh would<br>be requested internally before this delayed request<br>queued task was processed. As no transaction was in<br>progress this session refresh would be immediately<br>handled before the queued session refresh.<br><br>The code will now check if any delayed requests exist<br>before allowing a session refresh to immediately occur.<br>If any exist then the session refresh is queued.<br><br>ASTERISK-28730<br><br>Change-Id: Ic4a2423d54e750acef900d215333569ff97f6108<br>---<br>M res/res_pjsip_session.c<br>1 file changed, 34 insertions(+), 6 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/36/13736/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/res/res_pjsip_session.c b/res/res_pjsip_session.c</span><br><span>index b61b0fd..756bf82 100644</span><br><span>--- a/res/res_pjsip_session.c</span><br><span>+++ b/res/res_pjsip_session.c</span><br><span>@@ -61,6 +61,12 @@</span><br><span> enum ast_sip_session_response_priority response_priority);</span><br><span> static void handle_outgoing_request(struct ast_sip_session *session, pjsip_tx_data *tdata);</span><br><span> static void handle_outgoing_response(struct ast_sip_session *session, pjsip_tx_data *tdata);</span><br><span style="color: hsl(120, 100%, 40%);">+static int sip_session_refresh(struct ast_sip_session *session,</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_sip_session_request_creation_cb on_request_creation,</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_sip_session_sdp_creation_cb on_sdp_creation,</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_sip_session_response_cb on_response,</span><br><span style="color: hsl(120, 100%, 40%);">+ enum ast_sip_session_refresh_method method, int generate_new_sdp,</span><br><span style="color: hsl(120, 100%, 40%);">+ int queued);</span><br><span> </span><br><span> /*! \brief NAT hook for modifying outgoing messages with SDP */</span><br><span> static struct ast_sip_nat_hook *nat_hook;</span><br><span>@@ -556,14 +562,14 @@</span><br><span> </span><br><span> switch (delay->method) {</span><br><span> case DELAYED_METHOD_INVITE:</span><br><span style="color: hsl(0, 100%, 40%);">- ast_sip_session_refresh(session, delay->on_request_creation,</span><br><span style="color: hsl(120, 100%, 40%);">+ sip_session_refresh(session, delay->on_request_creation,</span><br><span> delay->on_sdp_creation, delay->on_response,</span><br><span style="color: hsl(0, 100%, 40%);">- AST_SIP_SESSION_REFRESH_METHOD_INVITE, delay->generate_new_sdp);</span><br><span style="color: hsl(120, 100%, 40%);">+ AST_SIP_SESSION_REFRESH_METHOD_INVITE, delay->generate_new_sdp, 1);</span><br><span> return 0;</span><br><span> case DELAYED_METHOD_UPDATE:</span><br><span style="color: hsl(0, 100%, 40%);">- ast_sip_session_refresh(session, delay->on_request_creation,</span><br><span style="color: hsl(120, 100%, 40%);">+ sip_session_refresh(session, delay->on_request_creation,</span><br><span> delay->on_sdp_creation, delay->on_response,</span><br><span style="color: hsl(0, 100%, 40%);">- AST_SIP_SESSION_REFRESH_METHOD_UPDATE, delay->generate_new_sdp);</span><br><span style="color: hsl(120, 100%, 40%);">+ AST_SIP_SESSION_REFRESH_METHOD_UPDATE, delay->generate_new_sdp, 1);</span><br><span> return 0;</span><br><span> case DELAYED_METHOD_BYE:</span><br><span> ast_sip_session_terminate(session, 0);</span><br><span>@@ -855,11 +861,11 @@</span><br><span> }</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-int ast_sip_session_refresh(struct ast_sip_session *session,</span><br><span style="color: hsl(120, 100%, 40%);">+static int sip_session_refresh(struct ast_sip_session *session,</span><br><span> ast_sip_session_request_creation_cb on_request_creation,</span><br><span> ast_sip_session_sdp_creation_cb on_sdp_creation,</span><br><span> ast_sip_session_response_cb on_response,</span><br><span style="color: hsl(0, 100%, 40%);">- enum ast_sip_session_refresh_method method, int generate_new_sdp)</span><br><span style="color: hsl(120, 100%, 40%);">+ enum ast_sip_session_refresh_method method, int generate_new_sdp, int queued)</span><br><span> {</span><br><span> pjsip_inv_session *inv_session = session->inv_session;</span><br><span> pjmedia_sdp_session *new_sdp = NULL;</span><br><span>@@ -882,6 +888,18 @@</span><br><span> ? DELAYED_METHOD_INVITE : DELAYED_METHOD_UPDATE);</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+ /* If this is a new session refresh attempt and there are outstanding delayed</span><br><span style="color: hsl(120, 100%, 40%);">+ * requests ensure they get processed first to ensure proper ordering</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!queued && !AST_LIST_EMPTY(&session->delayed_requests)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_debug(3, "Delay sending request to %s because of outstanding requests...\n",</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_sorcery_object_get_id(session->endpoint));</span><br><span style="color: hsl(120, 100%, 40%);">+ return delay_request(session, on_request_creation, on_sdp_creation, on_response,</span><br><span style="color: hsl(120, 100%, 40%);">+ generate_new_sdp,</span><br><span style="color: hsl(120, 100%, 40%);">+ method == AST_SIP_SESSION_REFRESH_METHOD_INVITE</span><br><span style="color: hsl(120, 100%, 40%);">+ ? DELAYED_METHOD_INVITE : DELAYED_METHOD_UPDATE);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> if (method == AST_SIP_SESSION_REFRESH_METHOD_INVITE) {</span><br><span> if (inv_session->invite_tsx) {</span><br><span> /* We can't send a reinvite yet, so delay it */</span><br><span>@@ -946,6 +964,16 @@</span><br><span> return 0;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+int ast_sip_session_refresh(struct ast_sip_session *session,</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_sip_session_request_creation_cb on_request_creation,</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_sip_session_sdp_creation_cb on_sdp_creation,</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_sip_session_response_cb on_response,</span><br><span style="color: hsl(120, 100%, 40%);">+ enum ast_sip_session_refresh_method method, int generate_new_sdp)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ return sip_session_refresh(session, on_request_creation, on_sdp_creation, on_response, method,</span><br><span style="color: hsl(120, 100%, 40%);">+ generate_new_sdp, 0);</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> int ast_sip_session_regenerate_answer(struct ast_sip_session *session,</span><br><span> ast_sip_session_sdp_creation_cb on_sdp_creation)</span><br><span> {</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/13736">change 13736</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/c/asterisk/+/13736"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 13 </div>
<div style="display:none"> Gerrit-Change-Id: Ic4a2423d54e750acef900d215333569ff97f6108 </div>
<div style="display:none"> Gerrit-Change-Number: 13736 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Joshua Colp <jcolp@sangoma.com> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>