[asterisk-dev] Interlocking of individual channels and the channels list in chan_sip.

Kirill Katsnelson kkm at adaptiveai.com
Thu Jun 16 02:41:33 CDT 2011


I got a deadlock, and do not understand how it can be prevented. Either 
that's deep in the design, or I am misunderstanding the rules of 
function calling that are violated.

The do_monitor thread gets a REFER on a channel X, then in 
handle_refer() gets its bridged channels locked, and calls 
ast_async_goto() on that channel. The latter creates a new channel, 
attempts to lock the channels list to insert the newly created one, and 
deadlocks.

Because another thread is in do_devstate_changes(), calls 
ast_channel_get_by_name_prefix(), which goes into __ao2_find(channels, 
...), that locks the channels list, then invokes ast_channel_cmp_cb() on 
every channel (including the channel X) and locks it. It deadlocks on an 
attempt to lock the channel. Now the 2 threads are in a first class 
deadlock.

I have not filed a bug yet, working on that. But I do not understand how 
this type of a deadlock is generally prevented. Since find_channel_... 
can be randomly called, the rule should be to never cause an attempted 
locking of the channels list while holding a lock on any channel. Correct?

  -kkm



More information about the asterisk-dev mailing list