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

[YSQL] lock-order-inversion observed in pgwrapper::PgSupervisor #16055

Open
deeps1991 opened this issue Feb 9, 2023 · 3 comments
Open

[YSQL] lock-order-inversion observed in pgwrapper::PgSupervisor #16055

deeps1991 opened this issue Feb 9, 2023 · 3 comments
Labels
area/ysql Yugabyte SQL (YSQL) kind/bug This issue is a bug priority/medium Medium priority issue

Comments

@deeps1991
Copy link
Contributor

deeps1991 commented Feb 9, 2023

Jira Link: DB-5450

Description

When trying to run YSQL tests on TSAN build, the following TSAN failure was observed in a few tests:

[ts-1] 2023-02-09 21:37:25.236 UTC [8491] LOG:  parameter "yb_test_block_index_phase" changed to "postbackfill"
[ts-1] 2023-02-09 21:37:25.236 UTC [8828] LOG:  blocking index state change indisready=true for 100ms
[ts-2] ==================
[ts-2] WARNING: ThreadSanitizer: lock-order-inversion (potential deadlock) (pid=8513)
[ts-2]   Cycle in lock order graph: M0 (0x7b5400002a48) => M1 (0x7b1800051f18) => M0
[ts-2]
[ts-2]   Mutex M1 acquired here while holding mutex M0 in main thread:
[ts-2]     #0 pthread_mutex_lock /opt/yb-build/llvm/yb-llvm-v15.0.3-yb-1-1667341687-0b8d1183-centos7-x86_64-build/src/llvm-project/compiler-rt/lib/tsan/rtl/../../sanitizer_common/sanitizer_common_interceptors.inc:4457:3 (yb-tserver+0xa4cfa)
[ts-2]     #1 std::mutex::lock() <null> (libc++.so.1+0x9ff19)
[ts-2]     #2 std::lock_guard<std::mutex>::lock_guard[abi:v15003](std::mutex&) /opt/yb-build/thirdparty/yugabyte-db-thirdparty-v20221115221900-32d6b89b02-centos7-x86_64-clang15/installed/tsan/libcxx/include/c++/v1/__mutex_base:94:27 (libyb_util.so+0x24dcd9)
[ts-2]     #3 yb::FlagsCallbackRegistry::RegisterCallback(void const*, string const&, std::function<void ()>) ${BUILD_ROOT}/../../src/yb/util/flags/flags_callback.cc:84:19 (libyb_util.so+0x24dcd9)
[ts-2]     #4 yb::RegisterFlagUpdateCallback(void const*, string const&, std::function<void ()>) ${BUILD_ROOT}/../../src/yb/util/flags/flags_callback.cc:184:24 (libyb_util.so+0x24f8c3)
[ts-2]     #5 yb::pgwrapper::PgSupervisor::RegisterReloadPgConfigCallback(void const*) ${BUILD_ROOT}/../../src/yb/yql/pgwrapper/pg_wrapper.cc:904:32 (libyb_pgwrapper.so+0x2f2f4)
[ts-2]     #6 yb::pgwrapper::PgSupervisor::RegisterPgFlagChangeNotifications() ${BUILD_ROOT}/../../src/yb/yql/pgwrapper/pg_wrapper.cc:919:7 (libyb_pgwrapper.so+0x2e69e)
[ts-2]     #7 yb::pgwrapper::PgSupervisor::Start() ${BUILD_ROOT}/../../src/yb/yql/pgwrapper/pg_wrapper.cc:749:3 (libyb_pgwrapper.so+0x2ce05)
[ts-2]     #8 yb::tserver::TabletServerMain(int, char**) ${BUILD_ROOT}/../../src/yb/tserver/tablet_server_main_impl.cc:271:5 (libtserver_main_impl.so+0x14d7b)
[ts-2]     #9 main ${BUILD_ROOT}/../../src/yb/tserver/tablet_server_main.cc:16:10 (yb-tserver+0x1077de)
[ts-2]
[ts-2]   Mutex M0 previously acquired by the same thread here:
[ts-2]     #0 pthread_mutex_lock /opt/yb-build/llvm/yb-llvm-v15.0.3-yb-1-1667341687-0b8d1183-centos7-x86_64-build/src/llvm-project/compiler-rt/lib/tsan/rtl/../../sanitizer_common/sanitizer_common_interceptors.inc:4457:3 (yb-tserver+0xa4cfa)
[ts-2]     #1 std::mutex::lock() <null> (libc++.so.1+0x9ff19)
[ts-2]     #2 std::lock_guard<std::mutex>::lock_guard[abi:v15003](std::mutex&) /opt/yb-build/thirdparty/yugabyte-db-thirdparty-v20221115221900-32d6b89b02-centos7-x86_64-clang15/installed/tsan/libcxx/include/c++/v1/__mutex_base:94:27 (libyb_pgwrapper.so+0x2cdaf)
[ts-2]     #3 yb::pgwrapper::PgSupervisor::Start() ${BUILD_ROOT}/../../src/yb/yql/pgwrapper/pg_wrapper.cc:746:31 (libyb_pgwrapper.so+0x2cdaf)
[ts-2]     #4 yb::tserver::TabletServerMain(int, char**) ${BUILD_ROOT}/../../src/yb/tserver/tablet_server_main_impl.cc:271:5 (libtserver_main_impl.so+0x14d7b)
[ts-2]     #5 main ${BUILD_ROOT}/../../src/yb/tserver/tablet_server_main.cc:16:10 (yb-tserver+0x1077de)
[ts-2]
[ts-2]   Mutex M0 acquired here while holding mutex M1 in thread T66:
[ts-2]     #0 pthread_mutex_lock /opt/yb-build/llvm/yb-llvm-v15.0.3-yb-1-1667341687-0b8d1183-centos7-x86_64-build/src/llvm-project/compiler-rt/lib/tsan/rtl/../../sanitizer_common/sanitizer_common_interceptors.inc:4457:3 (yb-tserver+0xa4cfa)
[ts-2]     #1 std::mutex::lock() <null> (libc++.so.1+0x9ff19)
[ts-2]     #2 std::lock_guard<std::mutex>::lock_guard[abi:v15003](std::mutex&) /opt/yb-build/thirdparty/yugabyte-db-thirdparty-v20221115221900-32d6b89b02-centos7-x86_64-clang15/installed/tsan/libcxx/include/c++/v1/__mutex_base:94:27 (libyb_pgwrapper.so+0x2f1b7)
[ts-2]     #3 yb::pgwrapper::PgSupervisor::UpdateAndReloadConfig() ${BUILD_ROOT}/../../src/yb/yql/pgwrapper/pg_wrapper.cc:894:31 (libyb_pgwrapper.so+0x2f1b7)
[ts-2]     #4 decltype(*std::declval<yb::pgwrapper::PgSupervisor*&>().*std::declval<yb::Status (yb::pgwrapper::PgSupervisor::*&)()>()()) std::__invoke[abi:v15003]<yb::Status (yb::pgwrapper::PgSupervisor::*&)(), yb::pgwrapper::PgSupervisor*&, void>(yb::Status (yb::pgwrapper::PgSupervisor::*&)(), yb::pgwrapper::PgSupervisor*&) /opt/yb-build/thirdparty/yugabyte-db-thirdparty-v20221115221900-32d6b89b02-centos7-x86_64-clang15/installed/tsan/libcxx/include/c++/v1/__functional/invoke.h:359:23 (libyb_pgwrapper.so+0x59acf)
[ts-2]     #5 std::__bind_return<yb::Status (yb::pgwrapper::PgSupervisor::*)(), std::tuple<yb::pgwrapper::PgSupervisor*>, std::tuple<>, __is_valid_bind_return<yb::Status (yb::pgwrapper::PgSupervisor::*)(), std::tuple<yb::pgwrapper::PgSupervisor*>, std::tuple<>>::value>::type std::__apply_functor[abi:v15003]<yb::Status (yb::pgwrapper::PgSupervisor::*)(), std::tuple<yb::pgwrapper::PgSupervisor*>, 0ul, std::tuple<>>(yb::Status (yb::pgwrapper::PgSupervisor::*&)(), std::tuple<yb::pgwrapper::PgSupervisor*>&, std::__tuple_indices<0ul>, std::tuple<>&&) /opt/yb-build/thirdparty/yugabyte-db-thirdparty-v20221115221900-32d6b89b02-centos7-x86_64-clang15/installed/tsan/libcxx/include/c++/v1/__functional/bind.h:263:12 (libyb_pgwrapper.so+0x59acf)
[ts-2]     #6 std::__bind_return<yb::Status (yb::pgwrapper::PgSupervisor::*)(), std::tuple<yb::pgwrapper::PgSupervisor*>, std::tuple<>, __is_valid_bind_return<yb::Status (yb::pgwrapper::PgSupervisor::*)(), std::tuple<yb::pgwrapper::PgSupervisor*>, std::tuple<>>::value>::type std::__bind<yb::Status (yb::pgwrapper::PgSupervisor::*)(), yb::pgwrapper::PgSupervisor*>::operator()[abi:v15003]<>() /opt/yb-build/thirdparty/yugabyte-db-thirdparty-v20221115221900-32d6b89b02-centos7-x86_64-clang15/installed/tsan/libcxx/include/c++/v1/__functional/bind.h:295:20 (libyb_pgwrapper.so+0x59acf)
[ts-2]     #7 decltype(std::declval<std::__bind<yb::Status (yb::pgwrapper::PgSupervisor::*)(), yb::pgwrapper::PgSupervisor*>&>()()) std::__invoke[abi:v15003]<std::__bind<yb::Status (yb::pgwrapper::PgSupervisor::*)(), yb::pgwrapper::PgSupervisor*>&>(std::__bind<yb::Status (yb::pgwrapper::PgSupervisor::*)(), yb::pgwrapper::PgSupervisor*>&) /opt/yb-build/thirdparty/yugabyte-db-thirdparty-v20221115221900-32d6b89b02-centos7-x86_64-clang15/installed/tsan/libcxx/include/c++/v1/__functional/invoke.h:394:23 (libyb_pgwrapper.so+0x59acf)
[ts-2]     #8 void std::__invoke_void_return_wrapper<void, true>::__call<std::__bind<yb::Status (yb::pgwrapper::PgSupervisor::*)(), yb::pgwrapper::PgSupervisor*>&>(std::__bind<yb::Status (yb::pgwrapper::PgSupervisor::*)(), yb::pgwrapper::PgSupervisor*>&) /opt/yb-build/thirdparty/yugabyte-db-thirdparty-v20221115221900-32d6b89b02-centos7-x86_64-clang15/installed/tsan/libcxx/include/c++/v1/__functional/invoke.h:479:9 (libyb_pgwrapper.so+0x59acf)
[ts-2]     #9 std::__function::__alloc_func<std::__bind<yb::Status (yb::pgwrapper::PgSupervisor::*)(), yb::pgwrapper::PgSupervisor*>, std::allocator<std::__bind<yb::Status (yb::pgwrapper::PgSupervisor::*)(), yb::pgwrapper::PgSupervisor*>>, void ()>::operator()[abi:v15003]() /opt/yb-build/thirdparty/yugabyte-db-thirdparty-v20221115221900-32d6b89b02-centos7-x86_64-clang15/installed/tsan/libcxx/include/c++/v1/__functional/function.h:185:16 (libyb_pgwrapper.so+0x59acf)
[ts-2]     #10 std::__function::__func<std::__bind<yb::Status (yb::pgwrapper::PgSupervisor::*)(), yb::pgwrapper::PgSupervisor*>, std::allocator<std::__bind<yb::Status (yb::pgwrapper::PgSupervisor::*)(), yb::pgwrapper::PgSupervisor*>>, void ()>::operator()() /opt/yb-build/thirdparty/yugabyte-db-thirdparty-v20221115221900-32d6b89b02-centos7-x86_64-clang15/installed/tsan/libcxx/include/c++/v1/__functional/function.h:359:12 (libyb_pgwrapper.so+0x59acf)
[ts-2]     #11 std::__function::__value_func<void ()>::operator()[abi:v15003]() const /opt/yb-build/thirdparty/yugabyte-db-thirdparty-v20221115221900-32d6b89b02-centos7-x86_64-clang15/installed/tsan/libcxx/include/c++/v1/__functional/function.h:512:16 (libyb_util.so+0x24f0af)
[ts-2]     #12 std::function<void ()>::operator()() const /opt/yb-build/thirdparty/yugabyte-db-thirdparty-v20221115221900-32d6b89b02-centos7-x86_64-clang15/installed/tsan/libcxx/include/c++/v1/__functional/function.h:1197:12 (libyb_util.so+0x24f0af)
[ts-2]     #13 yb::FlagsCallbackRegistry::InvokeCallbacks(void const*) ${BUILD_ROOT}/../../src/yb/util/flags/flags_callback.cc:128:7 (libyb_util.so+0x24f0af)
[ts-2]     #14 yb::flags_callback_internal::InvokeCallbacks(void const*, string const&) ${BUILD_ROOT}/../../src/yb/util/flags/flags_callback.cc:192:41 (libyb_util.so+0x24fcfe)
[ts-2]     #15 yb::flags_internal::SetFlagInternal(void const*, char const*, string const&, google::FlagSettingMode) ${BUILD_ROOT}/../../src/yb/util/flags/flags.cc:599:3 (libyb_util.so+0x246772)
[ts-2]     #16 yb::flags_internal::SetFlag(string const&, string const&, yb::StronglyTypedBool<yb::flags_internal::SetFlagForce_Tag>, string*, string*) ${BUILD_ROOT}/../../src/yb/util/flags/flags.cc:671:16 (libyb_util.so+0x247360)
[ts-2]     #17 yb::server::GenericServiceImpl::SetFlag(yb::server::SetFlagRequestPB const*, yb::server::SetFlagResponsePB*, yb::rpc::RpcContext) ${BUILD_ROOT}/../../src/yb/server/generic_service.cc:92:20 (libserver_process.so+0x7cd86)
[ts-2]     #18 yb::server::GenericServiceIf::InitMethods(scoped_refptr<yb::MetricEntity> const&)::$_0::operator()(std::shared_ptr<yb::rpc::InboundCall>) const::'lambda'(yb::server::SetFlagRequestPB const*, yb::server::SetFlagResponsePB*, yb::rpc::RpcContext)::operator()(yb::server::SetFlagRequestPB const*, yb::server::SetFlagResponsePB*, yb::rpc::RpcContext) const ${BUILD_ROOT}/src/yb/server/server_base.service.cc:228:9 (libserver_base_proto.so+0x54e37)
[ts-2]     #19 auto yb::rpc::HandleCall<yb::rpc::RpcCallPBParamsImpl<yb::server::SetFlagRequestPB, yb::server::SetFlagResponsePB>, yb::server::GenericServiceIf::InitMethods(scoped_refptr<yb::MetricEntity> const&)::$_0::operator()(std::shared_ptr<yb::rpc::InboundCall>) const::'lambda'(yb::server::SetFlagRequestPB const*, yb::server::SetFlagResponsePB*, yb::rpc::RpcContext)>(std::shared_ptr<yb::rpc::InboundCall>, yb::server::GenericServiceIf::InitMethods(scoped_refptr<yb::MetricEntity> const&)::$_0::operator()(std::shared_ptr<yb::rpc::InboundCall>) const::'lambda'(yb::server::SetFlagRequestPB const*, yb::server::SetFlagResponsePB*, yb::rpc::RpcContext)) ${BUILD_ROOT}/../../src/yb/rpc/local_call.h:115:7 (libserver_base_proto.so+0x54e37)
[ts-2]     #20 yb::server::GenericServiceIf::InitMethods(scoped_refptr<yb::MetricEntity> const&)::$_0::operator()(std::shared_ptr<yb::rpc::InboundCall>) const ${BUILD_ROOT}/src/yb/server/server_base.service.cc:226:7 (libserver_base_proto.so+0x54e37)
[ts-2]     #21 decltype(std::declval<yb::server::GenericServiceIf::InitMethods(scoped_refptr<yb::MetricEntity> const&)::$_0&>()(std::declval<std::shared_ptr<yb::rpc::InboundCall>>())) std::__invoke[abi:v15003]<yb::server::GenericServiceIf::InitMethods(scoped_refptr<yb::MetricEntity> const&)::$_0&, std::shared_ptr<yb::rpc::InboundCall>>(yb::server::GenericServiceIf::InitMethods(scoped_refptr<yb::MetricEntity> const&)::$_0&, std::shared_ptr<yb::rpc::InboundCall>&&) /opt/yb-build/thirdparty/yugabyte-db-thirdparty-v20221115221900-32d6b89b02-centos7-x86_64-clang15/installed/tsan/libcxx/include/c++/v1/__functional/invoke.h:394:23 (libserver_base_proto.so+0x54e37)
[ts-2]     #22 void std::__invoke_void_return_wrapper<void, true>::__call<yb::server::GenericServiceIf::InitMethods(scoped_refptr<yb::MetricEntity> const&)::$_0&, std::shared_ptr<yb::rpc::InboundCall>>(yb::server::GenericServiceIf::InitMethods(scoped_refptr<yb::MetricEntity> const&)::$_0&, std::shared_ptr<yb::rpc::InboundCall>&&) /opt/yb-build/thirdparty/yugabyte-db-thirdparty-v20221115221900-32d6b89b02-centos7-x86_64-clang15/installed/tsan/libcxx/include/c++/v1/__functional/invoke.h:479:9 (libserver_base_proto.so+0x54e37)
[ts-2]     #23 std::__function::__alloc_func<yb::server::GenericServiceIf::InitMethods(scoped_refptr<yb::MetricEntity> const&)::$_0, std::allocator<yb::server::GenericServiceIf::InitMethods(scoped_refptr<yb::MetricEntity> const&)::$_0>, void (std::shared_ptr<yb::rpc::InboundCall>)>::operator()[abi:v15003](std::shared_ptr<yb::rpc::InboundCall>&&) /opt/yb-build/thirdparty/yugabyte-db-thirdparty-v20221115221900-32d6b89b02-centos7-x86_64-clang15/installed/tsan/libcxx/include/c++/v1/__functional/function.h:185:16 (libserver_base_proto.so+0x54e37)
[ts-2]     #24 std::__function::__func<yb::server::GenericServiceIf::InitMethods(scoped_refptr<yb::MetricEntity> const&)::$_0, std::allocator<yb::server::GenericServiceIf::InitMethods(scoped_refptr<yb::MetricEntity> const&)::$_0>, void (std::shared_ptr<yb::rpc::InboundCall>)>::operator()(std::shared_ptr<yb::rpc::InboundCall>&&) /opt/yb-build/thirdparty/yugabyte-db-thirdparty-v20221115221900-32d6b89b02-centos7-x86_64-clang15/installed/tsan/libcxx/include/c++/v1/__functional/function.h:359:12 (libserver_base_proto.so+0x54e37)
[ts-2]     #25 std::__function::__value_func<void (std::shared_ptr<yb::rpc::InboundCall>)>::operator()[abi:v15003](std::shared_ptr<yb::rpc::InboundCall>&&) const /opt/yb-build/thirdparty/yugabyte-db-thirdparty-v20221115221900-32d6b89b02-centos7-x86_64-clang15/installed/tsan/libcxx/include/c++/v1/__functional/function.h:512:16 (libserver_base_proto.so+0x54812)
[ts-2]     #26 std::function<void (std::shared_ptr<yb::rpc::InboundCall>)>::operator()(std::shared_ptr<yb::rpc::InboundCall>) const /opt/yb-build/thirdparty/yugabyte-db-thirdparty-v20221115221900-32d6b89b02-centos7-x86_64-clang15/installed/tsan/libcxx/include/c++/v1/__functional/function.h:1197:12 (libserver_base_proto.so+0x54812)
[ts-2]     #27 yb::server::GenericServiceIf::Handle(std::shared_ptr<yb::rpc::InboundCall>) ${BUILD_ROOT}/src/yb/server/server_base.service.cc:211:3 (libserver_base_proto.so+0x54812)
[ts-2]     #28 yb::rpc::ServicePoolImpl::Handle(std::shared_ptr<yb::rpc::InboundCall>) ${BUILD_ROOT}/../../src/yb/rpc/service_pool.cc:263:19 (libyrpc.so+0x17a96a)
[ts-2]     #29 yb::rpc::InboundCall::InboundCallTask::Run() ${BUILD_ROOT}/../../src/yb/rpc/inbound_call.cc:236:13 (libyrpc.so+0xe7219)
[ts-2]     #30 yb::rpc::(anonymous namespace)::Worker::Execute() ${BUILD_ROOT}/../../src/yb/rpc/thread_pool.cc:104:15 (libyrpc.so+0x191314)
[ts-2]     #31 decltype(*std::declval<yb::rpc::(anonymous namespace)::Worker*&>().*std::declval<void (yb::rpc::(anonymous namespace)::Worker::*&)()>()()) std::__invoke[abi:v15003]<void (yb::rpc::(anonymous namespace)::Worker::*&)(), yb::rpc::(anonymous namespace)::Worker*&, void>(void (yb::rpc::(anonymous namespace)::Worker::*&)(), yb::rpc::(anonymous namespace)::Worker*&) /opt/yb-build/thirdparty/yugabyte-db-thirdparty-v20221115221900-32d6b89b02-centos7-x86_64-clang15/installed/tsan/libcxx/include/c++/v1/__functional/invoke.h:359:23 (libyrpc.so+0x19177b)
[ts-2]     #32 std::__bind_return<void (yb::rpc::(anonymous namespace)::Worker::*)(), std::tuple<yb::rpc::(anonymous namespace)::Worker*>, std::tuple<>, __is_valid_bind_return<void (yb::rpc::(anonymous namespace)::Worker::*)(), std::tuple<yb::rpc::(anonymous namespace)::Worker*>, std::tuple<>>::value>::type std::__apply_functor[abi:v15003]<void (yb::rpc::(anonymous namespace)::Worker::*)(), std::tuple<yb::rpc::(anonymous namespace)::Worker*>, 0ul, std::tuple<>>(void (yb::rpc::(anonymous namespace)::Worker::*&)(), std::tuple<yb::rpc::(anonymous namespace)::Worker*>&, std::__tuple_indices<0ul>, std::tuple<>&&) /opt/yb-build/thirdparty/yugabyte-db-thirdparty-v20221115221900-32d6b89b02-centos7-x86_64-clang15/installed/tsan/libcxx/include/c++/v1/__functional/bind.h:263:12 (libyrpc.so+0x19177b)
[ts-2]     #33 std::__bind_return<void (yb::rpc::(anonymous namespace)::Worker::*)(), std::tuple<yb::rpc::(anonymous namespace)::Worker*>, std::tuple<>, __is_valid_bind_return<void (yb::rpc::(anonymous namespace)::Worker::*)(), std::tuple<yb::rpc::(anonymous namespace)::Worker*>, std::tuple<>>::value>::type std::__bind<void (yb::rpc::(anonymous namespace)::Worker::* const&)(), yb::rpc::(anonymous namespace)::Worker* const&>::operator()[abi:v15003]<>() /opt/yb-build/thirdparty/yugabyte-db-thirdparty-v20221115221900-32d6b89b02-centos7-x86_64-clang15/installed/tsan/libcxx/include/c++/v1/__functional/bind.h:295:20 (libyrpc.so+0x19177b)
[ts-2]     #34 decltype(std::declval<std::__bind<void (yb::rpc::(anonymous namespace)::Worker::* const&)(), yb::rpc::(anonymous namespace)::Worker* const&>&>()()) std::__invoke[abi:v15003]<std::__bind<void (yb::rpc::(anonymous namespace)::Worker::* const&)(), yb::rpc::(anonymous namespace)::Worker* const&>&>(std::__bind<void (yb::rpc::(anonymous namespace)::Worker::* const&)(), yb::rpc::(anonymous namespace)::Worker* const&>&) /opt/yb-build/thirdparty/yugabyte-db-thirdparty-v20221115221900-32d6b89b02-centos7-x86_64-clang15/installed/tsan/libcxx/include/c++/v1/__functional/invoke.h:394:23 (libyrpc.so+0x19177b)
[ts-2]     #35 void std::__invoke_void_return_wrapper<void, true>::__call<std::__bind<void (yb::rpc::(anonymous namespace)::Worker::* const&)(), yb::rpc::(anonymous namespace)::Worker* const&>&>(std::__bind<void (yb::rpc::(anonymous namespace)::Worker::* const&)(), yb::rpc::(anonymous namespace)::Worker* const&>&) /opt/yb-build/thirdparty/yugabyte-db-thirdparty-v20221115221900-32d6b89b02-centos7-x86_64-clang15/installed/tsan/libcxx/include/c++/v1/__functional/invoke.h:479:9 (libyrpc.so+0x19177b)
[ts-2]     #36 std::__function::__alloc_func<std::__bind<void (yb::rpc::(anonymous namespace)::Worker::* const&)(), yb::rpc::(anonymous namespace)::Worker* const&>, std::allocator<std::__bind<void (yb::rpc::(anonymous namespace)::Worker::* const&)(), yb::rpc::(anonymous namespace)::Worker* const&>>, void ()>::operator()[abi:v15003]() /opt/yb-build/thirdparty/yugabyte-db-thirdparty-v20221115221900-32d6b89b02-centos7-x86_64-clang15/installed/tsan/libcxx/include/c++/v1/__functional/function.h:185:16 (libyrpc.so+0x19177b)
[ts-2]     #37 std::__function::__func<std::__bind<void (yb::rpc::(anonymous namespace)::Worker::* const&)(), yb::rpc::(anonymous namespace)::Worker* const&>, std::allocator<std::__bind<void (yb::rpc::(anonymous namespace)::Worker::* const&)(), yb::rpc::(anonymous namespace)::Worker* const&>>, void ()>::operator()() /opt/yb-build/thirdparty/yugabyte-db-thirdparty-v20221115221900-32d6b89b02-centos7-x86_64-clang15/installed/tsan/libcxx/include/c++/v1/__functional/function.h:359:12 (libyrpc.so+0x19177b)
[ts-2]     #38 std::__function::__value_func<void ()>::operator()[abi:v15003]() const /opt/yb-build/thirdparty/yugabyte-db-thirdparty-v20221115221900-32d6b89b02-centos7-x86_64-clang15/installed/tsan/libcxx/include/c++/v1/__functional/function.h:512:16 (libyb_util.so+0x355774)
[ts-2]     #39 std::function<void ()>::operator()() const /opt/yb-build/thirdparty/yugabyte-db-thirdparty-v20221115221900-32d6b89b02-centos7-x86_64-clang15/installed/tsan/libcxx/include/c++/v1/__functional/function.h:1197:12 (libyb_util.so+0x355774)
[ts-2]     #40 yb::Thread::SuperviseThread(void*) ${BUILD_ROOT}/../../src/yb/util/thread.cc:800:3 (libyb_util.so+0x355774)

Complete logs can be found in the attached files
PgIndexBackfillTest_Permissions.log
PgWrapperFlagsTest_VerifyGFlagRuntimeTag.log
PgIndexBackfillTest_PgStatProgressCreateIndexPartitioned.log

@deeps1991 deeps1991 added area/ysql Yugabyte SQL (YSQL) status/awaiting-triage Issue awaiting triage labels Feb 9, 2023
@yugabyte-ci yugabyte-ci added kind/bug This issue is a bug priority/medium Medium priority issue labels Feb 9, 2023
@deeps1991
Copy link
Contributor Author

@jaki @hari90

@hari90
Copy link
Contributor

hari90 commented Feb 10, 2023

Start can only be called once so we can never actually deadlock on this. Can we suppress this?

@yugabyte-ci yugabyte-ci removed the status/awaiting-triage Issue awaiting triage label Feb 22, 2023
deeps1991 added a commit that referenced this issue Jun 8, 2023
Summary:
TSAN detects this possible deadlock in PgWrapper::Supervisor:

Minimal stack trace:

```
WARNING: ThreadSanitizer: lock-order-inversion (potential deadlock) (pid=8513)
[ts-2]   Cycle in lock order graph: M0 (0x7b5400002a48) => M1 (0x7b1800051f18) => M0

Mutex M1 acquired here while holding mutex M0 in main thread:
[ts-2]     #0 pthread_mutex_lock /opt/yb-build/llvm/yb-llvm-v15.0.3-yb-1-1667341687-0b8d1183-centos7-x86_64-build/src/llvm-project/compiler-rt/lib/tsan/rtl/../../sanitizer_common/sanitizer_common_interceptors.inc:4457:3 (yb-tserver+0xa4cfa)
[ts-2]     #3 yb::FlagsCallbackRegistry::RegisterCallback(void const*, string const&, std::function<void ()>) ${BUILD_ROOT}/../../src/yb/util/flags/flags_callback.cc:84:19 (libyb_util.so+0x24dcd9)
[ts-2]     #4 yb::RegisterFlagUpdateCallback(void const*, string const&, std::function<void ()>) ${BUILD_ROOT}/../../src/yb/util/flags/flags_callback.cc:184:24 (libyb_util.so+0x24f8c3)
[ts-2]     #5 yb::pgwrapper::PgSupervisor::RegisterReloadPgConfigCallback(void const*) ${BUILD_ROOT}/../../src/yb/yql/pgwrapper/pg_wrapper.cc:904:32 (libyb_pgwrapper.so+0x2f2f4)
[ts-2]     #6 yb::pgwrapper::PgSupervisor::RegisterPgFlagChangeNotifications() ${BUILD_ROOT}/../../src/yb/yql/pgwrapper/pg_wrapper.cc:919:7 (libyb_pgwrapper.so+0x2e69e)
[ts-2]     #7 yb::pgwrapper::PgSupervisor::Start() ${BUILD_ROOT}/../../src/yb/yql/pgwrapper/pg_wrapper.cc:749:3 (libyb_pgwrapper.so+0x2ce05)

Mutex M0 previously acquired by the same thread here:
[ts-2]     #0 pthread_mutex_lock /opt/yb-build/llvm/yb-llvm-v15.0.3-yb-1-1667341687-0b8d1183-centos7-x86_64-build/src/llvm-project/compiler-rt/lib/tsan/rtl/../../sanitizer_common/sanitizer_common_interceptors.inc:4457:3 (yb-tserver+0xa4cfa)
[ts-2]     #3 yb::pgwrapper::PgSupervisor::Start() ${BUILD_ROOT}/../../src/yb/yql/pgwrapper/pg_wrapper.cc:746:31 (libyb_pgwrapper.so+0x2cdaf)

Mutex M0 acquired here while holding mutex M1 in thread T66:
[ts-2]     #0 pthread_mutex_lock /opt/yb-build/llvm/yb-llvm-v15.0.3-yb-1-1667341687-0b8d1183-centos7-x86_64-build/src/llvm-project/compiler-rt/lib/tsan/rtl/../../sanitizer_common/sanitizer_common_interceptors.inc:4457:3 (yb-tserver+0xa4cfa)
[ts-2]     #3 yb::pgwrapper::PgSupervisor::UpdateAndReloadConfig() ${BUILD_ROOT}/../../src/yb/yql/pgwrapper/pg_wrapper.cc:894:31 (libyb_pgwrapper.so+0x2f1b7)

```
TSAN detects that there are two functions (Start() and UpdateAndReloadConfig)
each acquiring M0 and M1 in inverse order which may run into a deadlock. However, Start() is always
called first and will acquire M0 and M1 before it registers the callback that invokes
UpdateAndReloadConfig(). Start() will never be called again. Thus the deadlock
called out by TSAN is not possible.
Jira: DB-5450

Test Plan: Tested with TSAN build in Detective runs of D22913

Reviewers: hsunder, mbautin

Reviewed By: hsunder

Subscribers: yql

Differential Revision: https://phorge.dev.yugabyte.com/D25311
@deeps1991 deeps1991 reopened this Jun 16, 2023
@deeps1991
Copy link
Contributor Author

deeps1991 commented Jun 16, 2023

It looks like the above fix did not work, the issue can still be observed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/ysql Yugabyte SQL (YSQL) kind/bug This issue is a bug priority/medium Medium priority issue
Projects
None yet
Development

No branches or pull requests

3 participants