<p>Friendly Automation <strong>submitted</strong> this change.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/18891">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span></span><br></pre><div style="white-space:pre-wrap">Approvals:
  Joshua Colp: Looks good to me, but someone else must approve
  George Joseph: Looks good to me, approved
  Friendly Automation: Approved for Submit

</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">res_pjsip_pubsub: Postpone destruction of old subscriptions on RLS update<br><br>Set termination state to old subscriptions to prevent queueing and sending<br>NOTIFY messages on exten/device state changes.<br><br>Postpone destruction of old subscriptions until all already queued tasks<br>that may be using old subscriptions have completed.<br><br>ASTERISK-29906<br><br>Change-Id: I96582aad3a26515ca73a8460ee6756f56f6ba23b<br>---<br>M res/res_pjsip_exten_state.c<br>M res/res_pjsip_pubsub.c<br>2 files changed, 47 insertions(+), 2 deletions(-)<br><br></pre>
<pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/res/res_pjsip_exten_state.c b/res/res_pjsip_exten_state.c</span><br><span>index b51df87..3c7baee 100644</span><br><span>--- a/res/res_pjsip_exten_state.c</span><br><span>+++ b/res/res_pjsip_exten_state.c</span><br><span>@@ -296,7 +296,8 @@</span><br><span>               .body_data = &task_data->exten_state_data,</span><br><span>    };</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-  /* Terminated subscriptions are no longer associated with a valid tree, and sending</span><br><span style="color: hsl(120, 100%, 40%);">+   /* The subscription was terminated while notify_task was in queue.</span><br><span style="color: hsl(120, 100%, 40%);">+       Terminated subscriptions are no longer associated with a valid tree, and sending</span><br><span>   * NOTIFY messages on a subscription which has already been terminated won't work.</span><br><span>        */</span><br><span>  if (ast_sip_subscription_is_terminated(task_data->exten_state_sub->sip_sub)) {</span><br><span>@@ -339,6 +340,13 @@</span><br><span>  struct notify_task_data *task_data;</span><br><span>  struct exten_state_subscription *exten_state_sub = data;</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+  /* Terminated subscriptions are no longer associated with a valid tree.</span><br><span style="color: hsl(120, 100%, 40%);">+        * Do not queue notify_task.</span><br><span style="color: hsl(120, 100%, 40%);">+   */</span><br><span style="color: hsl(120, 100%, 40%);">+   if (ast_sip_subscription_is_terminated(exten_state_sub->sip_sub)) {</span><br><span style="color: hsl(120, 100%, 40%);">+                return 0;</span><br><span style="color: hsl(120, 100%, 40%);">+     }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span>  if (!(task_data = alloc_notify_task_data(exten, exten_state_sub, info))) {</span><br><span>           return -1;</span><br><span>   }</span><br><span>diff --git a/res/res_pjsip_pubsub.c b/res/res_pjsip_pubsub.c</span><br><span>index d0f3717..4086445 100644</span><br><span>--- a/res/res_pjsip_pubsub.c</span><br><span>+++ b/res/res_pjsip_pubsub.c</span><br><span>@@ -3994,6 +3994,15 @@</span><br><span>      return 0;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+static int destroy_subscriptions_task(void *obj)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+       struct ast_sip_subscription *sub = (struct ast_sip_subscription *) obj;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+     destroy_subscriptions(sub);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ return 0;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> /*!</span><br><span>  * \brief Called whenever an in-dialog SUBSCRIBE is received</span><br><span>  *</span><br><span>@@ -4067,8 +4076,19 @@</span><br><span>                                                         AST_SCHED_DEL_UNREF(sched, sub_tree->notify_sched_id, ao2_ref(sub_tree, -1));</span><br><span>                                                     sub_tree->send_scheduled_notify = 0;</span><br><span>                                              }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+                                           /* Terminate old subscriptions to stop sending NOTIFY messages on exten/device state changes */</span><br><span style="color: hsl(120, 100%, 40%);">+                                               set_state_terminated(old_root);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+                                             /* Shutdown old subscriptions to remove exten/device state change callbacks</span><br><span style="color: hsl(120, 100%, 40%);">+                                            that can queue tasks for old subscriptions */</span><br><span>                                               shutdown_subscriptions(old_root);</span><br><span style="color: hsl(0, 100%, 40%);">-                                               destroy_subscriptions(old_root);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+                                            /* Postpone destruction until all already queued tasks that may be using old subscriptions have completed */</span><br><span style="color: hsl(120, 100%, 40%);">+                                          if (ast_sip_push_task(sub_tree->serializer, destroy_subscriptions_task, old_root)) {</span><br><span style="color: hsl(120, 100%, 40%);">+                                                       ast_log(LOG_ERROR, "Failed to push task to destroy old subscriptions for RLS '%s->%s'.\n",</span><br><span style="color: hsl(120, 100%, 40%);">+                                                               ast_sorcery_object_get_id(endpoint), old_root->resource);</span><br><span style="color: hsl(120, 100%, 40%);">+                                          }</span><br><span>                                    } else {</span><br><span>                                             destroy_subscriptions(new_root);</span><br><span>                                     }</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/18891">change 18891</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/+/18891"/><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: I96582aad3a26515ca73a8460ee6756f56f6ba23b </div>
<div style="display:none"> Gerrit-Change-Number: 18891 </div>
<div style="display:none"> Gerrit-PatchSet: 5 </div>
<div style="display:none"> Gerrit-Owner: Alexei Gradinari <alex2grad@gmail.com> </div>
<div style="display:none"> Gerrit-Reviewer: Friendly Automation </div>
<div style="display:none"> Gerrit-Reviewer: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Joshua Colp <jcolp@sangoma.com> </div>
<div style="display:none"> Gerrit-Reviewer: N A <mail@interlinked.x10host.com> </div>
<div style="display:none"> Gerrit-MessageType: merged </div>