[asterisk-dev] IAX different reentrant locks depth in the same function

Richard Mudgett rmudgett at digium.com
Tue Apr 21 16:45:39 CDT 2015


On Tue, Apr 21, 2015 at 2:42 PM, Yousf Ateya <y.ateya at starkbits.com> wrote:

> While testing the patch of
> https://issues.asterisk.org/jira/browse/ASTERISK-24983, I found that in
> some paths (ex. in call hangup procedure) we acquire the lock multiple
> times from the same thread.
>
> The lock implementation supports reentrant locks, so it works; until you
> stuck in a deadlock!
>
> For example (lock iaxs[callno]), the function iax2_destroy_helper is
> called from multiple paths:
>   1 - iax2_hangup -> iax2_destroy_helper : In this path the lock is locked
> only once (in iax2_hangup).
>
>   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.
>
> 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!!
>
> Why? Because you need to unlock it twice in path 2!
>
> Personally, I didn't like it that much.
>
> Is it common, and we live with it (will do a work around for this specific
> case)?
>
> Or this seems trouble making pattern and we should have deeper look
> (probably in IAX and other components)?
>

This is an architectural problem in chan_iax2 that causes it to hold
onto locks to prevent things from disappearing on you (I think it is
mostly iaxs[callno] becoming NULL).  The design pre-dates ao2
objects!  Simply unlocking locks to avoid a deadlock can lead to
things disappearing.  I don't think there will be an easy solution.

Richard
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-dev/attachments/20150421/7d689c2f/attachment.html>


More information about the asterisk-dev mailing list