<p>Leif Einar Aune has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/15302">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">app_queue: Remove lock on queues to avoid deadlock.<br><br>When analysing coredumps with gdb from situations<br>where asterisk stops handling queue calls it is observed that the threads are<br>blocked waiting for the mutex for the queues. The normal pattern is to<br>iterate over the queues, find a suitable queue, lock the queue, handle call<br>then unlock the queue. The mutex for the queues is implicitly locked by the<br>ao2_iterator functionality while iterating.<br><br>_queues_show() was however locking the queues collections first, then<br>iterating using the flag AO2_ITERATOR_DONTLOCK and locking the specific<br>queue in each iteration.<br><br>This resulted in the deadlock where the _queues_show() was waiting for a<br>specific queue mutex, while holding the queues mutex, and the other threads<br>were waiting for the queues mutex.<br><br>This patch uses the 'lock queues for each iteration' idiom in the function<br>_queues_show() instead of locking the queues collection before iterating.<br>It has been run succesfully in production with busy queues, and the observed<br>locking of queue call handling were no longer present.<br><br>ASTERISK-22976<br>Reported-by: Aaron An<br><br>Change-Id: I9b3583a20176f7c26442b7e406bb35fd7f8833b6<br>---<br>M apps/app_queue.c<br>1 file changed, 1 insertion(+), 3 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/02/15302/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/apps/app_queue.c b/apps/app_queue.c</span><br><span>index 4db468f..cbb39db 100644</span><br><span>--- a/apps/app_queue.c</span><br><span>+++ b/apps/app_queue.c</span><br><span>@@ -9251,8 +9251,7 @@</span><br><span> }</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- ao2_lock(queues);</span><br><span style="color: hsl(0, 100%, 40%);">- queue_iter = ao2_iterator_init(queues, AO2_ITERATOR_DONTLOCK);</span><br><span style="color: hsl(120, 100%, 40%);">+ queue_iter = ao2_iterator_init(queues, 0);</span><br><span> while ((q = ao2_t_iterator_next(&queue_iter, "Iterate through queues"))) {</span><br><span> float sl;</span><br><span> struct call_queue *realtime_queue = NULL;</span><br><span>@@ -9356,7 +9355,6 @@</span><br><span> queue_t_unref(q, "Done with iterator"); /* Unref the iterator's reference */</span><br><span> }</span><br><span> ao2_iterator_destroy(&queue_iter);</span><br><span style="color: hsl(0, 100%, 40%);">- ao2_unlock(queues);</span><br><span> if (!found) {</span><br><span> if (argc == 3) {</span><br><span> ast_str_set(&out, 0, "No such queue: %s.", argv[2]);</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/15302">change 15302</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/+/15302"/><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: I9b3583a20176f7c26442b7e406bb35fd7f8833b6 </div>
<div style="display:none"> Gerrit-Change-Number: 15302 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Leif Einar Aune <leif.einar@telemagic.no> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>