[Home]

Summary:ASTERISK-25780: stasis: Potential deadlock
Reporter:Badalian Vyacheslav (slavon)Labels:
Date Opened:2016-02-11 23:08:46.000-0600Date Closed:2016-02-15 11:28:43.000-0600
Priority:MinorRegression?
Status:Closed/CompleteComponents:Core/Stasis
Versions:13.7.2 Frequency of
Occurrence
Related
Issues:
is duplicated byASTERISK-25776 lock-order-inversion (potential deadlock) when loading app_queue
Environment:[root@vm-asterisk04t asterisk]# git branch -v * master a394865 Merge "Resources/res_phoneprov: fix memory leak and heap-use-after-free" Attachments:
Description:{code}
==================
WARNING: ThreadSanitizer: lock-order-inversion (potential deadlock) (pid=12427)
 Cycle in lock order graph: M295847 (0x7d2800185060) => M1075 (0x7d640004ba00) => M1074 (0x7d280007cf60) => M295847

 Mutex M1075 acquired here while holding mutex M295847 in main thread:
   #0 pthread_mutex_lock <null> (libtsan.so.0+0x000000037816)
   #1 __ast_pthread_mutex_lock /root/asterisk/main/lock.c:313 (asterisk+0x000000503d01)
   #2 __ao2_lock /root/asterisk/main/astobj2.c:200 (asterisk+0x0000002d78be)
   #3 stasis_topic_pool_get_topic /root/asterisk/main/stasis.c:1140 (asterisk+0x00000063a9b8)
   #4 ast_device_state_topic /root/asterisk/main/devicestate.c:710 (asterisk+0x0000004524e6)
   #5 device_state_aggregate_publish /root/asterisk/main/devicestate.c:805 (asterisk+0x000000452976)
   #6 caching_topic_exec /root/asterisk/main/stasis_cache.c:853 (asterisk+0x00000064b702)
   #7 subscription_invoke /root/asterisk/main/stasis.c:433 (asterisk+0x000000635f0d)
   #8 dispatch_message /root/asterisk/main/stasis.c:754 (asterisk+0x000000637e86)
   #9 publish_msg /root/asterisk/main/stasis.c:822 (asterisk+0x00000063838f)
   #10 stasis_publish /root/asterisk/main/stasis.c:830 (asterisk+0x00000063846e)
   #11 ast_publish_device_state_full /root/asterisk/main/devicestate.c:766 (asterisk+0x00000045279e)
   #12 ast_devstate_changed_literal /root/asterisk/main/devicestate.c:500 (asterisk+0x00000045139c)
   #13 ast_devstate_changed /root/asterisk/main/devicestate.c:532 (asterisk+0x0000004516f2)
   #14 <null> <null> (app_queue.so+0x000000037e97)
   #15 <null> <null> (app_queue.so+0x0000000734e1)
   #16 <null> <null> (app_queue.so+0x00000007436f)
   #17 <null> <null> (app_queue.so+0x000000074822)
   #18 <null> <null> (app_queue.so+0x000000082025)
   #19 start_resource /root/asterisk/main/loader.c:1015 (asterisk+0x0000004ff12f)
   #20 load_resource_list /root/asterisk/main/loader.c:1213 (asterisk+0x000000500c7c)
   #21 load_modules /root/asterisk/main/loader.c:1366 (asterisk+0x000000501ade)
   #22 asterisk_daemon /root/asterisk/main/asterisk.c:4659 (asterisk+0x0000002d6e5d)
   #23 main /root/asterisk/main/asterisk.c:4230 (asterisk+0x0000002d5cfd)

 Mutex M295847 previously acquired by the same thread here:
   #0 pthread_mutex_lock <null> (libtsan.so.0+0x000000037816)
   #1 __ast_pthread_mutex_lock /root/asterisk/main/lock.c:313 (asterisk+0x000000503d01)
   #2 __ao2_lock /root/asterisk/main/astobj2.c:200 (asterisk+0x0000002d78be)
   #3 publish_msg /root/asterisk/main/stasis.c:816 (asterisk+0x0000006382df)
   #4 stasis_publish /root/asterisk/main/stasis.c:830 (asterisk+0x00000063846e)
   #5 ast_publish_device_state_full /root/asterisk/main/devicestate.c:766 (asterisk+0x00000045279e)
   #6 ast_devstate_changed_literal /root/asterisk/main/devicestate.c:500 (asterisk+0x00000045139c)
   #7 ast_devstate_changed /root/asterisk/main/devicestate.c:532 (asterisk+0x0000004516f2)
   #8 <null> <null> (app_queue.so+0x000000037e97)
   #9 <null> <null> (app_queue.so+0x0000000734e1)
   #10 <null> <null> (app_queue.so+0x00000007436f)
   #11 <null> <null> (app_queue.so+0x000000074822)
   #12 <null> <null> (app_queue.so+0x000000082025)
   #13 start_resource /root/asterisk/main/loader.c:1015 (asterisk+0x0000004ff12f)
   #14 load_resource_list /root/asterisk/main/loader.c:1213 (asterisk+0x000000500c7c)
   #15 load_modules /root/asterisk/main/loader.c:1366 (asterisk+0x000000501ade)
   #16 asterisk_daemon /root/asterisk/main/asterisk.c:4659 (asterisk+0x0000002d6e5d)
   #17 main /root/asterisk/main/asterisk.c:4230 (asterisk+0x0000002d5cfd)

 Mutex M1074 acquired here while holding mutex M1075 in main thread:
   #0 pthread_mutex_lock <null> (libtsan.so.0+0x000000037816)
   #1 __ast_pthread_mutex_lock /root/asterisk/main/lock.c:313 (asterisk+0x000000503d01)
   #2 __ao2_lock /root/asterisk/main/astobj2.c:200 (asterisk+0x0000002d78be)
   #3 stasis_forward_all /root/asterisk/main/stasis.c:919 (asterisk+0x000000638f4b)
   #4 stasis_topic_pool_get_topic /root/asterisk/main/stasis.c:1157 (asterisk+0x00000063ac4f)
   #5 ast_device_state_topic /root/asterisk/main/devicestate.c:710 (asterisk+0x0000004524e6)
   #6 ast_publish_device_state_full /root/asterisk/main/devicestate.c:761 (asterisk+0x00000045276d)
   #7 ast_devstate_changed_literal /root/asterisk/main/devicestate.c:500 (asterisk+0x00000045139c)
   #8 ast_devstate_changed /root/asterisk/main/devicestate.c:532 (asterisk+0x0000004516f2)
   #9 <null> <null> (app_queue.so+0x000000037e97)
   #10 <null> <null> (app_queue.so+0x0000000734e1)
   #11 <null> <null> (app_queue.so+0x00000007436f)
   #12 <null> <null> (app_queue.so+0x000000074822)
   #13 <null> <null> (app_queue.so+0x000000082025)
   #14 start_resource /root/asterisk/main/loader.c:1015 (asterisk+0x0000004ff12f)
   #15 load_resource_list /root/asterisk/main/loader.c:1213 (asterisk+0x000000500c7c)
   #16 load_modules /root/asterisk/main/loader.c:1366 (asterisk+0x000000501ade)
   #17 asterisk_daemon /root/asterisk/main/asterisk.c:4659 (asterisk+0x0000002d6e5d)
   #18 main /root/asterisk/main/asterisk.c:4230 (asterisk+0x0000002d5cfd)

 Mutex M1075 previously acquired by the same thread here:
   #0 pthread_mutex_lock <null> (libtsan.so.0+0x000000037816)
   #1 __ast_pthread_mutex_lock /root/asterisk/main/lock.c:313 (asterisk+0x000000503d01)
   #2 __ao2_lock /root/asterisk/main/astobj2.c:200 (asterisk+0x0000002d78be)
   #3 stasis_topic_pool_get_topic /root/asterisk/main/stasis.c:1140 (asterisk+0x00000063a9b8)
   #4 ast_device_state_topic /root/asterisk/main/devicestate.c:710 (asterisk+0x0000004524e6)
   #5 ast_publish_device_state_full /root/asterisk/main/devicestate.c:761 (asterisk+0x00000045276d)
   #6 ast_devstate_changed_literal /root/asterisk/main/devicestate.c:500 (asterisk+0x00000045139c)
   #7 ast_devstate_changed /root/asterisk/main/devicestate.c:532 (asterisk+0x0000004516f2)
   #8 <null> <null> (app_queue.so+0x000000037e97)
   #9 <null> <null> (app_queue.so+0x0000000734e1)
   #10 <null> <null> (app_queue.so+0x00000007436f)
   #11 <null> <null> (app_queue.so+0x000000074822)
   #12 <null> <null> (app_queue.so+0x000000082025)
   #13 start_resource /root/asterisk/main/loader.c:1015 (asterisk+0x0000004ff12f)
   #14 load_resource_list /root/asterisk/main/loader.c:1213 (asterisk+0x000000500c7c)
   #15 load_modules /root/asterisk/main/loader.c:1366 (asterisk+0x000000501ade)
   #16 asterisk_daemon /root/asterisk/main/asterisk.c:4659 (asterisk+0x0000002d6e5d)
   #17 main /root/asterisk/main/asterisk.c:4230 (asterisk+0x0000002d5cfd)

 Mutex M295847 acquired here while holding mutex M1074 in main thread:
   #0 pthread_mutex_lock <null> (libtsan.so.0+0x000000037816)
   #1 __ast_pthread_mutex_lock /root/asterisk/main/lock.c:313 (asterisk+0x000000503d01)
   #2 __ao2_lock /root/asterisk/main/astobj2.c:200 (asterisk+0x0000002d78be)
   #3 topic_add_subscription /root/asterisk/main/stasis.c:660 (asterisk+0x00000063716c)
   #4 topic_add_subscription /root/asterisk/main/stasis.c:671 (asterisk+0x0000006375bf)
   #5 internal_stasis_subscribe /root/asterisk/main/stasis.c:503 (asterisk+0x000000636532)
   #6 stasis_subscribe /root/asterisk/main/stasis.c:517 (asterisk+0x000000636608)
   #7 <null> <null> (app_queue.so+0x0000000826a6)
   #8 start_resource /root/asterisk/main/loader.c:1015 (asterisk+0x0000004ff12f)
   #9 load_resource_list /root/asterisk/main/loader.c:1213 (asterisk+0x000000500c7c)
   #10 load_modules /root/asterisk/main/loader.c:1366 (asterisk+0x000000501ade)
   #11 asterisk_daemon /root/asterisk/main/asterisk.c:4659 (asterisk+0x0000002d6e5d)
   #12 main /root/asterisk/main/asterisk.c:4230 (asterisk+0x0000002d5cfd)

 Mutex M1074 previously acquired by the same thread here:
   #0 pthread_mutex_lock <null> (libtsan.so.0+0x000000037816)
   #1 __ast_pthread_mutex_lock /root/asterisk/main/lock.c:313 (asterisk+0x000000503d01)
   #2 __ao2_lock /root/asterisk/main/astobj2.c:200 (asterisk+0x0000002d78be)
   #3 topic_add_subscription /root/asterisk/main/stasis.c:660 (asterisk+0x00000063716c)
   #4 internal_stasis_subscribe /root/asterisk/main/stasis.c:503 (asterisk+0x000000636532)
   #5 stasis_subscribe /root/asterisk/main/stasis.c:517 (asterisk+0x000000636608)
   #6 <null> <null> (app_queue.so+0x0000000826a6)
   #7 start_resource /root/asterisk/main/loader.c:1015 (asterisk+0x0000004ff12f)
   #8 load_resource_list /root/asterisk/main/loader.c:1213 (asterisk+0x000000500c7c)
   #9 load_modules /root/asterisk/main/loader.c:1366 (asterisk+0x000000501ade)
   #10 asterisk_daemon /root/asterisk/main/asterisk.c:4659 (asterisk+0x0000002d6e5d)
   #11 main /root/asterisk/main/asterisk.c:4230 (asterisk+0x0000002d5cfd)

SUMMARY: ThreadSanitizer: lock-order-inversion (potential deadlock) ??:0 __interceptor_pthread_mutex_lock
==================

{code}
Comments:By: Asterisk Team (asteriskteam) 2016-02-11 23:08:47.806-0600

Thanks for creating a report! The issue has entered the triage process. That means the issue will wait in this status until a Bug Marshal has an opportunity to review the issue. Once the issue has been reviewed you will receive comments regarding the next steps towards resolution.

A good first step is for you to review the [Asterisk Issue Guidelines|https://wiki.asterisk.org/wiki/display/AST/Asterisk+Issue+Guidelines] if you haven't already. The guidelines detail what is expected from an Asterisk issue report.

Then, if you are submitting a patch, please review the [Patch Contribution Process|https://wiki.asterisk.org/wiki/display/AST/Patch+Contribution+Process].

By: Joshua C. Colp (jcolp) 2016-02-15 11:28:43.538-0600

The code appears to account for this situation already and performs dead lock avoidance when juggling the relevant locks.