[asterisk-dev] main/pbx.c locking order query

Steve Davies davies147 at gmail.com
Mon Mar 21 08:52:05 CDT 2011


main/pbx.c contains the following comment:

/* WARNING:
   When holding this container's lock, do _not_ do anything that will
cause conlock
   to be taken, unless you _already_ hold it. The ast_merge_contexts_and_delete
   function will take the locks in conlock/hints order, so any other
   paths that require both locks must also take them in that order.
*/
static struct ao2_container *hints;

The above comment used to be true, but when hints were converted fully
to ao2, that locking order changed as part of the fix. Therefore I
believe that as of 1.6.2.18-rc1, the comment is not true. I believe it
should read:

/* WARNING:
   Do _not_ try to get this container's lock while holding the
conlock. There is a
   natural locking order, which results in conlock being locked
periodically while
   looping through hints. As a result, the ast_merge_contexts_and_delete
   function will take the locks in hints/conlock order, so any other
   paths that require both locks must also take them in that order.
*/
static struct ao2_container *hints;


And then, the ao2_lock(hints) lock needs moving to before the conlock
lock in ast_merge_contexts_and_delete().

Thoughts? TBH I have not yet seen this cause a problem, but it feels
like it needs to be done to correct a potential deadlock.

Regards,
Steve



More information about the asterisk-dev mailing list