<p>George Joseph has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/15400">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">res_pjsip_refer: Always serialize calls to refer_progress_notify<br><br>refer_progress_notify wasn't always being called from the progress<br>serializer. This could allow clearing notification->progress->sub<br>in one thread while another was trying to use it.<br><br>* refer_progress_notify is now called using the new function<br> ast_sip_push_task_serializer() which runs the callback<br> in-line if it's already called from the serializer and<br> pushes it to the serializer (without a wait) if it isn't.<br><br>Change-Id: Idcf1934c4e873f2c82e2d106f8d9f040caf9fa1e<br>---<br>M include/asterisk/res_pjsip.h<br>M res/res_pjsip.c<br>M res/res_pjsip_refer.c<br>3 files changed, 63 insertions(+), 7 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/00/15400/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/include/asterisk/res_pjsip.h b/include/asterisk/res_pjsip.h</span><br><span>index 81161f3..8b17110 100644</span><br><span>--- a/include/asterisk/res_pjsip.h</span><br><span>+++ b/include/asterisk/res_pjsip.h</span><br><span>@@ -1674,6 +1674,25 @@</span><br><span> int ast_sip_push_task_wait_serializer(struct ast_taskprocessor *serializer, int (*sip_task)(void *), void *task_data);</span><br><span> </span><br><span> /*!</span><br><span style="color: hsl(120, 100%, 40%);">+ * \brief Push a task to the serializer but don't wait for it to complete.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * Like \ref ast_sip_push_task_wait_serializer except that it doesn't block.</span><br><span style="color: hsl(120, 100%, 40%);">+ * If the specified serializer is the current thread then the task executes.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param serializer The SIP serializer to execute the task. NULL if</span><br><span style="color: hsl(120, 100%, 40%);">+ * any of the default serializers can be used.</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param sip_task The task to execute</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param task_data The parameter to pass to the task when it executes</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \note The sip_task() return value may need to be distinguished from</span><br><span style="color: hsl(120, 100%, 40%);">+ * the failure to push the task.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \return sip_task() return value on success.</span><br><span style="color: hsl(120, 100%, 40%);">+ * \retval -1 Failure to push the task.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+int ast_sip_push_task_serializer(struct ast_taskprocessor *serializer, int (*sip_task)(void *), void *task_data);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/*!</span><br><span> * \brief Determine if the current thread is a SIP servant thread</span><br><span> *</span><br><span> * \retval 0 This is not a SIP servant thread</span><br><span>diff --git a/res/res_pjsip.c b/res/res_pjsip.c</span><br><span>index 2ea07fd..33e74e9 100644</span><br><span>--- a/res/res_pjsip.c</span><br><span>+++ b/res/res_pjsip.c</span><br><span>@@ -4759,6 +4759,28 @@</span><br><span> return ast_sip_push_task_wait(serializer, sip_task, task_data);</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+int ast_sip_push_task_serializer(struct ast_taskprocessor *serializer, int (*sip_task)(void *), void *task_data)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!serializer) {</span><br><span style="color: hsl(120, 100%, 40%);">+ /* Caller doesn't care which PJSIP serializer the task executes under. */</span><br><span style="color: hsl(120, 100%, 40%);">+ serializer = ast_serializer_pool_get(sip_serializer_pool);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!serializer) {</span><br><span style="color: hsl(120, 100%, 40%);">+ /* No serializer picked to execute the task */</span><br><span style="color: hsl(120, 100%, 40%);">+ return -1;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ if (ast_taskprocessor_is_task(serializer)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ /*</span><br><span style="color: hsl(120, 100%, 40%);">+ * We are the requested serializer so we must execute</span><br><span style="color: hsl(120, 100%, 40%);">+ * the task now or deadlock waiting on ourself to</span><br><span style="color: hsl(120, 100%, 40%);">+ * execute it.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+ return sip_task(task_data);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ return ast_sip_push_task(serializer, sip_task, task_data);</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> void ast_copy_pj_str(char *dest, const pj_str_t *src, size_t size)</span><br><span> {</span><br><span> size_t chars_to_copy = MIN(size - 1, pj_strlen(src));</span><br><span>diff --git a/res/res_pjsip_refer.c b/res/res_pjsip_refer.c</span><br><span>index 5d98f9e..f6dd2f3 100644</span><br><span>--- a/res/res_pjsip_refer.c</span><br><span>+++ b/res/res_pjsip_refer.c</span><br><span>@@ -127,8 +127,11 @@</span><br><span> * but we are already running a task... thus it would deadlock */</span><br><span> if (notification->state == PJSIP_EVSUB_STATE_TERMINATED) {</span><br><span> ast_debug(3, "Subscription '%p' is being terminated as a result of a NOTIFY, removing REFER progress structure early on progress monitor '%p'\n",</span><br><span style="color: hsl(0, 100%, 40%);">- notification->progress->sub, notification->progress);</span><br><span style="color: hsl(120, 100%, 40%);">+ sub, notification->progress);</span><br><span> pjsip_dlg_inc_lock(notification->progress->dlg);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!notification->progress->sub) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_log(LOG_WARNING, "Subscription %p was stepped on!", sub);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span> pjsip_evsub_set_mod_data(notification->progress->sub, refer_progress_module.id, NULL);</span><br><span> pjsip_dlg_dec_lock(notification->progress->dlg);</span><br><span> </span><br><span>@@ -560,7 +563,9 @@</span><br><span> notification = refer_progress_notification_alloc(attended->progress, response,</span><br><span> PJSIP_EVSUB_STATE_TERMINATED);</span><br><span> if (notification) {</span><br><span style="color: hsl(0, 100%, 40%);">- refer_progress_notify(notification);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (ast_sip_push_task_serializer(attended->progress->serializer, refer_progress_notify, notification)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_cleanup(notification);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span> }</span><br><span> }</span><br><span> </span><br><span>@@ -616,7 +621,9 @@</span><br><span> PJSIP_EVSUB_STATE_TERMINATED);</span><br><span> </span><br><span> if (notification) {</span><br><span style="color: hsl(0, 100%, 40%);">- refer_progress_notify(notification);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (ast_sip_push_task_serializer(refer->progress->serializer, refer_progress_notify, notification)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_cleanup(notification);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span> }</span><br><span> } else if (refer->progress) {</span><br><span> /* If attended transfer and progress monitoring is being done attach a frame hook so we can monitor it */</span><br><span>@@ -637,7 +644,9 @@</span><br><span> ast_channel_name(chan));</span><br><span> </span><br><span> if (notification) {</span><br><span style="color: hsl(0, 100%, 40%);">- refer_progress_notify(notification);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (ast_sip_push_task_serializer(refer->progress->serializer, refer_progress_notify, notification)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_cleanup(notification);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span> }</span><br><span> }</span><br><span> </span><br><span>@@ -660,7 +669,9 @@</span><br><span> ast_channel_name(chan));</span><br><span> </span><br><span> if (notification) {</span><br><span style="color: hsl(0, 100%, 40%);">- refer_progress_notify(notification);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (ast_sip_push_task_serializer(refer->progress->serializer, refer_progress_notify, notification)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_cleanup(notification);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span> }</span><br><span> </span><br><span> ao2_cleanup(refer->progress);</span><br><span>@@ -680,7 +691,9 @@</span><br><span> ast_channel_name(chan));</span><br><span> </span><br><span> if (notification) {</span><br><span style="color: hsl(0, 100%, 40%);">- refer_progress_notify(notification);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (ast_sip_push_task_serializer(refer->progress->serializer, refer_progress_notify, notification)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_cleanup(notification);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span> }</span><br><span> </span><br><span> ast_channel_lock(chan);</span><br><span>@@ -1155,7 +1168,9 @@</span><br><span> </span><br><span> if (notification) {</span><br><span> /* The refer_progress_notify function will call ao2_cleanup on this for us */</span><br><span style="color: hsl(0, 100%, 40%);">- refer_progress_notify(notification);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (ast_sip_push_task_serializer(progress->serializer, refer_progress_notify, notification)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_cleanup(notification);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span> }</span><br><span> }</span><br><span> </span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/15400">change 15400</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/+/15400"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 16 </div>
<div style="display:none"> Gerrit-Change-Id: Idcf1934c4e873f2c82e2d106f8d9f040caf9fa1e </div>
<div style="display:none"> Gerrit-Change-Number: 15400 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>