ACE中ACE_Message_Queue 的notify和Reactor結合使用時會導致死鎖 - [程序]

版權聲明:轉載時請以超鏈接形式標明文章原始出處和作者信息及本聲明
http://chenm.blogbus.com/logs/50407912.html

  • 現象


設置了Queue的通知策略之後,在putq之後會調用Reactor的notify方法,Reactor內部使用一個管道來傳輸通知事件,導致在寫入通知事件時阻塞在該管道上,從而導致程序掛起。
這是一個很早就發現的bug,但是一直沒有被修改。一方面是它不好修改,另一方面是ACE的維護者缺乏資金解決這個問題。

  • 一個示例的調用棧:

(gdb) thr app all bt

Thread 4 (Thread 0xb7ad3b90 (LWP 31160)):   # ---- Scheduler thread.
#0  0xb80da430 in __kernel_vsyscall ()
#1  0xb7f790e5 in pthread_cond_wait@@GLIBC_2.3.2 () from /lib/tls/i686/cmov/libpthread.so.0
#2  0x08070c59 in ACE_OS::cond_wait (cv=0x91a7cbc, external_mutex=0x91a7ca0)
    at /home/cm/ACE_wrappers/ace/OS_NS_Thread.inl:329
#3  0x08070c9f in ACE_Condition<ACE_Thread_Mutex>::wait (this=0x91a7cbc)
    at /home/cm/ACE_wrappers/ace/Condition_T.cpp:90
#4  0x0807020a in cm::Scheduler::choose_processor (this=0x91a7c54)
    at /home/cm/Dropbox/projects/ace_skel/src/Scheduler.cpp:94
#5  0x080705ad in cm::Scheduler::svc (this=0x91a7c54)
    at /home/cm/Dropbox/projects/ace_skel/src/Scheduler.cpp:80
#6  0xb7daae52 in ACE_Task_Base::svc_run (args=0x91a7c54) at Task.cpp:275
#7  0xb7dac2ed in ACE_Thread_Adapter::invoke_i (this=0x91a7fa0) at Thread_Adapter.cpp:149
#8  0xb7dac366 in ACE_Thread_Adapter::invoke (this=0x91a7fa0) at Thread_Adapter.cpp:98
#9  0xb7d33271 in ace_thread_adapter (args=0x91a7fa0) at Base_Thread_Adapter.cpp:124
#10 0xb7f754ff in start_thread () from /lib/tls/i686/cmov/libpthread.so.0
#11 0xb7ef049e in clone () from /lib/tls/i686/cmov/libc.so.6

Thread 3 (Thread 0xb72d2b90 (LWP 31161)):   # ---- Processor thread.
#0  0xb80da430 in __kernel_vsyscall ()
#1  0xb7f7c07b in write () from /lib/tls/i686/cmov/libpthread.so.0
#2  0xb7d212ea in ACE::send (handle=6, buf=0xb72cff34, n=8, timeout=0x8)
    at /home/cm/ACE_wrappers/ace/OS_NS_unistd.inl:1200
#3  0xb7d4da29 in ACE_Dev_Poll_Reactor_Notify::notify (this=0x91a3c10, eh=0x92095b0, mask=2, 
    timeout=0x0) at Dev_Poll_Reactor.cpp:165
#4  0xb7d4bcbc in ACE_Dev_Poll_Reactor::notify (this=0x91a3980, eh=0x92095b0, mask=2, 
    timeout=0x0) at Dev_Poll_Reactor.cpp:2028
#5  0xb7d9550e in ACE_Reactor::notify (this=0x91a38c0, event_handler=0x92095b0, mask=2, tv=0x0)
    at Reactor.cpp:481
#6  0xb7d95e76 in ACE_Reactor_Notification_Strategy::notify (this=0x9209638)
    at Reactor_Notification_Strategy.cpp:28
#7  0x08062d47 in ACE_Message_Queue<ACE_MT_SYNCH>::notify (this=0x9209660)
    at /home/cm/ACE_wrappers/ace/Message_Queue_T.cpp:1998
#8  0x080650cc in ACE_Message_Queue<ACE_MT_SYNCH>::enqueue_tail (this=0x9209660, 
    new_item=0xb61bb3d8, timeout=0xb72d0064)
    at /home/cm/ACE_wrappers/ace/Message_Queue_T.cpp:1888
#9  0x08076c2c in ACE_Task<ACE_MT_SYNCH>::putq (this=0x92095b0, mb=0xb61bb3d8, tv=0xb72d0064)
    at /home/cm/ACE_wrappers/ace/Task_T.inl:36
#10 0x08075653 in cm::RequestHandler::async_send (this=0x92095b0, mb=0xb61bb3d8)
    at /home/cm/Dropbox/projects/ace_skel/src/RequestHandler.cpp:257
#11 0x080746ef in cm::HttpTransaction::send_static_file (this=0x9209d10, uri=@0xb72d2288)
    at /home/cm/Dropbox/projects/ace_skel/src/HttpTransaction.cpp:98
#12 0x08074c8b in cm::HttpTransaction::execute (this=0x9209d10)
    at /home/cm/Dropbox/projects/ace_skel/src/HttpTransaction.cpp:37
#13 0x080712a0 in cm::Processor::svc (this=0x91aa128)
    at /home/cm/Dropbox/projects/ace_skel/src/Processor.cpp:47
#14 0xb7daae52 in ACE_Task_Base::svc_run (args=0x91aa128) at Task.cpp:275
#15 0xb7dac2ed in ACE_Thread_Adapter::invoke_i (this=0x91aa330) at Thread_Adapter.cpp:149
#16 0xb7dac366 in ACE_Thread_Adapter::invoke (this=0x91aa330) at Thread_Adapter.cpp:98
#17 0xb7d33271 in ace_thread_adapter (args=0x91aa330) at Base_Thread_Adapter.cpp:124
#18 0xb7f754ff in start_thread () from /lib/tls/i686/cmov/libpthread.so.0
#19 0xb7ef049e in clone () from /lib/tls/i686/cmov/libc.so.6

Thread 2 (Thread 0xb6ad1b90 (LWP 31162)):   # ---- Processor thread
#0  0xb80da430 in __kernel_vsyscall ()
#1  0xb7f7c07b in write () from /lib/tls/i686/cmov/libpthread.so.0
#2  0xb7d212ea in ACE::send (handle=6, buf=0xb6acef34, n=8, timeout=0x8)
    at /home/cm/ACE_wrappers/ace/OS_NS_unistd.inl:1200
#3  0xb7d4da29 in ACE_Dev_Poll_Reactor_Notify::notify (this=0x91a3c10, eh=0x9209448, mask=2, 
    timeout=0x0) at Dev_Poll_Reactor.cpp:165
#4  0xb7d4bcbc in ACE_Dev_Poll_Reactor::notify (this=0x91a3980, eh=0x9209448, mask=2, 
    timeout=0x0) at Dev_Poll_Reactor.cpp:2028
#5  0xb7d9550e in ACE_Reactor::notify (this=0x91a38c0, event_handler=0x9209448, mask=2, tv=0x0)
    at Reactor.cpp:481
#6  0xb7d95e76 in ACE_Reactor_Notification_Strategy::notify (this=0x92094d0)
    at Reactor_Notification_Strategy.cpp:28
#7  0x08062d47 in ACE_Message_Queue<ACE_MT_SYNCH>::notify (this=0x92094f8)
    at /home/cm/ACE_wrappers/ace/Message_Queue_T.cpp:1998
#8  0x080650cc in ACE_Message_Queue<ACE_MT_SYNCH>::enqueue_tail (this=0x92094f8, 
    new_item=0x92f5c38, timeout=0xb6acf064)
    at /home/cm/ACE_wrappers/ace/Message_Queue_T.cpp:1888
#9  0x08076c2c in ACE_Task<ACE_MT_SYNCH>::putq (this=0x9209448, mb=0x92f5c38, tv=0xb6acf064)
    at /home/cm/ACE_wrappers/ace/Task_T.inl:36
#10 0x08075653 in cm::RequestHandler::async_send (this=0x9209448, mb=0x92f5c38)
    at /home/cm/Dropbox/projects/ace_skel/src/RequestHandler.cpp:257
#11 0x08074917 in cm::HttpTransaction::send_static_file (this=0x9209bc0, uri=@0xb6ad1288)
    at /home/cm/Dropbox/projects/ace_skel/src/HttpTransaction.cpp:110
#12 0x08074c8b in cm::HttpTransaction::execute (this=0x9209bc0)
    at /home/cm/Dropbox/projects/ace_skel/src/HttpTransaction.cpp:37
#13 0x080712a0 in cm::Processor::svc (this=0x91ac488)
    at /home/cm/Dropbox/projects/ace_skel/src/Processor.cpp:47
#14 0xb7daae52 in ACE_Task_Base::svc_run (args=0x91ac488) at Task.cpp:275
#15 0xb7dac2ed in ACE_Thread_Adapter::invoke_i (this=0x91ac690) at Thread_Adapter.cpp:149
#16 0xb7dac366 in ACE_Thread_Adapter::invoke (this=0x91ac690) at Thread_Adapter.cpp:98
#17 0xb7d33271 in ace_thread_adapter (args=0x91ac690) at Base_Thread_Adapter.cpp:124
#18 0xb7f754ff in start_thread () from /lib/tls/i686/cmov/libpthread.so.0
#19 0xb7ef049e in clone () from /lib/tls/i686/cmov/libc.so.6

Thread 1 (Thread 0xb7ad48e0 (LWP 31159)):  # ---- Reactor thread.
#0  0xb80da430 in __kernel_vsyscall ()
#1  0xb7f790e5 in pthread_cond_wait@@GLIBC_2.3.2 () from /lib/tls/i686/cmov/libpthread.so.0
#2  0xb7d3c254 in ACE_Condition_Thread_Mutex::wait (this=0x91ae99c, mutex=@0x80, abstime=0x0)
---Type <return> to continue, or q <return> to quit---
    at /home/cm/ACE_wrappers/ace/OS_NS_Thread.inl:362
#3  0xb7d3c2bb in ACE_Condition_Thread_Mutex::wait (this=0x91ae99c, abstime=0x0)
    at Condition_Thread_Mutex.cpp:107
#4  0x08063c90 in ACE_Message_Queue<ACE_MT_SYNCH>::wait_not_full_cond (this=0x91ae920, 
    timeout=0x0) at /home/cm/ACE_wrappers/ace/Message_Queue_T.cpp:1715
#5  0x08064e38 in ACE_Message_Queue<ACE_MT_SYNCH>::enqueue_head (this=0x91ae920, 
    new_item=0xb6105610, timeout=0x0) at /home/cm/ACE_wrappers/ace/Message_Queue_T.cpp:1777
#6  0x0807236a in ACE_Task<ACE_MT_SYNCH>::ungetq (this=0x91ae870, mb=0xb6105610, tv=0x0)
    at /home/cm/ACE_wrappers/ace/Task_T.inl:43
#7  0x08071d5d in cm::HttpRequestHandler::handle_output (this=0x91ae870)
    at /home/cm/Dropbox/projects/ace_skel/src/HttpRequestHandler.cpp:86
#8  0xb7d4d982 in ACE_Dev_Poll_Reactor_Notify::dispatch_notify (this=0x91a3c10, 
    buffer=@0xbfaf5c04) at Dev_Poll_Reactor.cpp:365
#9  0xb7d4c91b in ACE_Dev_Poll_Reactor_Notify::handle_input (this=0x91a3c10, handle=5)
    at Dev_Poll_Reactor.cpp:297
#10 0xb7d4f945 in ACE_Dev_Poll_Reactor::dispatch_io_event (this=0x91a3980, guard=@0xbfaf5d14)
    at /home/cm/ACE_wrappers/ace/Dev_Poll_Reactor.inl:126
#11 0xb7d4fb4c in ACE_Dev_Poll_Reactor::dispatch (this=0x91a3980, guard=@0xbfaf5d14)
    at Dev_Poll_Reactor.cpp:1079
#12 0xb7d4fca6 in ACE_Dev_Poll_Reactor::handle_events_i (this=0x91a3980, max_wait_time=0x0, 
    guard=@0xbfaf5d14) at Dev_Poll_Reactor.cpp:1056
#13 0xb7d4fd7c in ACE_Dev_Poll_Reactor::handle_events (this=0x91a3980, max_wait_time=0x0)
    at Dev_Poll_Reactor.cpp:1012
#14 0xb7d94fc3 in ACE_Reactor::run_reactor_event_loop (this=0x91a38c0, eh=0) at Reactor.cpp:224
#15 0x08062452 in main (argc=7, argv=0xbfaf5f04)
    at /home/cm/Dropbox/projects/ace_skel/src/main.cpp:75
#0  0xb80da430 in __kernel_vsyscall ()

  • 規避方法

把ACE_Message_Queue的high water level設置爲一個很高的值,避免隊列滿觸發該bug。

 

  • 參考

http://groups.google.com/group/comp.soft-sys.ace/browse_thread/thread/3575b21beae71683?pli=1
http://groups.google.com/group/comp.soft-sys.ace/browse_thread/thread/38fb11cf258f3eec

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章