<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Apr 21, 2015 at 2:42 PM, Yousf Ateya <span dir="ltr"><<a href="mailto:y.ateya@starkbits.com" target="_blank">y.ateya@starkbits.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><div><div><div><div>While testing the patch of <a href="https://issues.asterisk.org/jira/browse/ASTERISK-24983" target="_blank">https://issues.asterisk.org/jira/browse/ASTERISK-24983</a>, I found that in some paths (ex. in call hangup procedure) we acquire the lock multiple times from the same thread.<br><br></div>The lock implementation supports reentrant locks, so it works; until you stuck in a deadlock!<br><br></div>For example (lock iaxs[callno]), the function iax2_destroy_helper is called from multiple paths:<br></div>  1 - iax2_hangup -> iax2_destroy_helper : In this path the lock is locked only once (in iax2_hangup).<br><br></div>  2 - socket_process_helper (ACK for hangup) -> iax2_destroy -> pvt_destructor (because of ao2_ref(pvt,-1) -> iax2_destroy_helper : In this path lock is locked twice, one in socket_process_helper and the other in pvt_destructor.<br><br></div>The problem of this is that in function iax2_destroy_helper, I wanted to avoid deadlock with other thread (sending scheduled lagrq), so I did ast_mutex_unlock. But I still got deadlock!!<br><br></div>Why? Because you need to unlock it twice in  path 2!<br><br><div><div><div><div><div><div><div>Personally, I didn't like it that much.<br><br></div><div>Is it common, and we live with it (will do a work around for this specific case)?<br><br>Or this  seems trouble making pattern and we should have deeper look (probably in IAX and other components)?<span class="HOEnZb"><font color="#888888"><br></font></span></div></div></div></div></div></div></div></div></blockquote><div><br></div><div>This is an architectural problem in chan_iax2 that causes it to hold<br>onto locks  to prevent things from disappearing on you (I think it is<br>mostly iaxs[callno] becoming NULL).  The design pre-dates ao2<br>objects!  Simply unlocking locks to avoid a deadlock can lead to<br>things disappearing.  I don't think there will be an easy solution.<br></div><div><br></div><div>Richard<br></div></div><br></div></div>