Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pc_notify_with_timeout inside pc_client_poll will never returns. #65

Closed
xpol opened this issue Apr 28, 2016 · 6 comments
Closed

pc_notify_with_timeout inside pc_client_poll will never returns. #65

xpol opened this issue Apr 28, 2016 · 6 comments

Comments

@xpol
Copy link
Contributor

xpol commented Apr 28, 2016

The stack trace:

#0  0x00007fff8f016de6 in __psynch_mutexwait ()
#1  0x00000000000cecc2 in _pthread_mutex_lock_wait ()
#2  0x00000000000cc294 in _pthread_mutex_lock_slow ()
#3  0x000000010186867a in pc_mutex_lock [inlined] at /Users/xpol/Workspace/lua-packages/packages/pomelo/deps/libpomelo2/src/pc_mutex.h:67
#4  0x0000000101868671 in tr_uv_tcp_send at /Users/xpol/Workspace/lua-packages/packages/pomelo/deps/libpomelo2/src/tr/uv/tr_uv_tcp_i.c:366
#5  0x0000000101862b3a in pc_notify_with_timeout at /Users/xpol/Workspace/lua-packages/packages/pomelo/deps/libpomelo2/src/pc_pomelo.c:716
#6  0x000000010187c627 in Client_notify(lua_State*) at /Users/xpol/Workspace/lua-packages/packages/pomelo/lua-pomelo.cpp:657
#7  0x00000001017e96b8 in lj_BC_FUNCC ()
#8  0x00000001017f9984 in lua_pcall ()
#9  0x000000010187d34d in lua_request_cb(pc_request_s const*, int, char const*) at /Users/xpol/Workspace/lua-packages/packages/pomelo/lua-pomelo.cpp:570
#10 0x00000001018638ac in pc__trans_resp at /Users/xpol/Workspace/lua-packages/packages/pomelo/deps/libpomelo2/src/pc_trans.c:333
#11 0x0000000101861d45 in pc__handle_event [inlined] at /Users/xpol/Workspace/lua-packages/packages/pomelo/deps/libpomelo2/src/pc_pomelo.c:310
#12 0x0000000101861d22 in pc_client_poll at /Users/xpol/Workspace/lua-packages/packages/pomelo/deps/libpomelo2/src/pc_pomelo.c:374
#13 0x000000010187c229 in pomelo_poll() at /Users/xpol/Workspace/lua-packages/packages/pomelo/lua-pomelo.cpp:126
#14 0x000000010187dbc9 in lib_poll(lua_State*) at /Users/xpol/Workspace/lua-packages/packages/pomelo/lua-pomelo.cpp:134
#15 0x00000001017e96b8 in lj_BC_FUNCC ()
#16 0x00000001017f9984 in lua_pcall ()

just like #63.

The polling mode is completely unstable and untested...

@cynron
Copy link
Member

cynron commented Apr 28, 2016

pc_client_cleanup will wait the uv loop to terminate, if you call pc_client_cleanup in callbacks, it will deadlock.

@xpol
Copy link
Contributor Author

xpol commented Apr 28, 2016

it is pc_notify_with_timeout this time, not pc_client_cleanup.

@cynron
Copy link
Member

cynron commented Apr 28, 2016

there are two mutexes here, polling_event_queue_mutex and tcp_send_queue_mutex
there are two threads, polling thread, uv loop thread

polling thread:
acquire event queue mutex -> invoke callback -> call pc_notify_with_timeout -> want send queue mutex

uv loop thread:
accquire send queue mutex -> uv tcp send ok -> add send complete event -> want event queue mutex

then, deadlock!

solution:
uv loop thread: after fetch a send item, release the send queue mutex

@cynron
Copy link
Member

cynron commented Apr 28, 2016

solution 2:
when polling the event queue, release the event_mutex before pc__handle_event and re-acquire it after pc__handle_event finished.

@xpol
Copy link
Contributor Author

xpol commented Apr 29, 2016

here is a pr for solution 2: #67.

@cynron
Copy link
Member

cynron commented Apr 29, 2016

ok, goto #67 ,closing here

@cynron cynron closed this as completed Apr 29, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants