Fix deadlock issue 98/262498/6
authorHwankyu Jhun <h.jhun@samsung.com>
Thu, 12 Aug 2021 06:06:38 +0000 (15:06 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Fri, 13 Aug 2021 01:56:53 +0000 (10:56 +0900)
commit696a464a2b28909a8ec6e40c66f936e907558685
tree18c7743445dda2033ecc6e632883d99d809242d0
parent52792fc5b7631836a169680a78c7780c84f7906c
Fix deadlock issue

When the rpc_port_proxy_connect() is called in the sub thread,
the port appeared event can be received in the main thread.
In this case, the process can be a deadlock state as below:
+------------------------------------------------------------------------------+
| -- #0  0xb5d3e6c8 in __lll_lock_wait () from /usr/lib/libpthread-2.30.so     |
| -- #1  0xb5d35de4 in __pthread_mutex_lock () from /usr/lib/libpthread-2.30.so|
| -- #2  0xa63ee315 in _ZN8rpc_port8internal5Proxy14OnPortAppearedEPKcS3_iPv ()|
|                      from /usr/lib/librpc-port.so.1.9.3        |
| -- #3  0xb5f69721 in _ZN12_GLOBAL__N_19WatchInfo8AppComCbEPKc20aul_app_com_re|
|                      sult_eP9_bundle_tPv () from /usr/lib/libaul.so.0.38.0   |
| -- #4  0xb5f74d2d in app_com_recv () from /usr/lib/libaul.so.0.38.0          |
| -- #5  0xb5f74fe7 in __dispatch_request () from /usr/lib/libaul.so.0.38.0    |
| -- #6  0xb5b10fb3 in g_main_context_dispatch () from /usr/lib/libglib-2.0.so.|
                       0.6200.3                                                |
| -- #7  0xb58a01a9 in _ecore_glib_select.lto_priv.0 () from /usr/lib/libecore.|
|                      so.1.25.1                                               |
| -- #8  0xb589f037 in _ecore_main_select () from /usr/lib/libecore.so.1.25.1  |
| -- #9  0xb589f8c7 in _ecore_main_loop_iterate_internal () from /usr/lib/libec|
|                      ore.so.1.25.1                                           |
| -- [pthread wait detected] pthread_mutex_lock/pthread_join owner tid:1412    |
+------------------------------------------------------------------------------+
| -- [User Backtrace] [Thread state:S (sleeping), Frozen:No]                   |
| -- Pid: 683, Tid: 1412, comm: Parallel[0] exec_start[69.429195162]           |
| -- #0  0xb5d3e6c8 in __lll_lock_wait () from /usr/lib/libpthread-2.30.so     |
| -- #1  0xb5d35de4 in __pthread_mutex_lock () from /usr/lib/libpthread-2.30.so|
| -- #2  0xb5f789b5 in aul_app_com_leave () from /usr/lib/libaul.so.0.38.0     |
| -- #3  0xb5f6d197 in aul_rpc_port_remove_watch () from /usr/lib/libaul.so.0.3|
|                      8.0                                                     |
| -- #4  0xa63ec503 in _ZN8rpc_port8internal5Proxy6CancelEv () from /usr/lib/li|
|                      brpc-port.so.1.9.3                                      |
| -- #5  0xa63ee329 in _ZN8rpc_port8internal5Proxy14OnPortAppearedEPKcS3_iPv ()|
|                      from /usr/lib/librpc-port.so.1.9.3                      |
| -- #6  0xa63ee45b in _ZN8rpc_port8internal5Proxy5WatchEv () from /usr/lib/lib|
|                      rpc-port.so.1.9.3                                       |
| -- #7  0xa63ee58f in _ZN8rpc_port8internal5Proxy7ConnectENSt7__cxx1112basic_s|
|                      tringIcSt11char_traitsIcESaIcEEES7_PNS1_14IEventListener|
|                      E () from /usr/lib/librpc-port.so.1.9.3                 |
| -- #8  0xa63efd51 in rpc_port_proxy_connect () from /usr/lib/librpc-port.so.1|
|                      .9.3                                                    |
+------------------------------------------------------------------------------+

This patch fixes the proxy handle management using the shared_ptr. And,
the port check is moved to the main thread to avoid the deadlock issue.

Change-Id: I8ef7f775491427e48eb5894c66dc1629d172a4d5
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
src/proxy-internal.cc
src/proxy-internal.hh
src/rpc-port.cc