-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Labels
Description
This is a shared global boolean flag that multiple threads write to, setting to 1. While this should usually work, it's technically undefined behavior and Clang TSAN flags this as problematic, here's an example TSAN backtrace from Envoy:
WARNING: ThreadSanitizer: data race (pid=583)
Write of size 1 at 0x0000045b3308 by thread T8 (mutexes: write M2486):
#0 event_del_nolock_ /build/tmp/_bazel_bazel/b570b5ccd0454dc9af9f65ab1833764d/execroot/envoy/external/com_github_libevent_libevent/event.c (uds_integration_test+0x38b03d1)
#1 event_process_active_single_queue /build/tmp/_bazel_bazel/b570b5ccd0454dc9af9f65ab1833764d/execroot/envoy/external/com_github_libevent_libevent/event.c:1608:5 (uds_integration_test+0x38b9d31)
#2 event_process_active /build/tmp/_bazel_bazel/b570b5ccd0454dc9af9f65ab1833764d/execroot/envoy/external/com_github_libevent_libevent/event.c:1738:9 (uds_integration_test+0x38b3f92)
#3 event_base_loop /build/tmp/_bazel_bazel/b570b5ccd0454dc9af9f65ab1833764d/execroot/envoy/external/com_github_libevent_libevent/event.c:1961 (uds_integration_test+0x38b3f92)
#4 Envoy::Event::DispatcherImpl::run(Envoy::Event::Dispatcher::RunType) /proc/self/cwd/source/common/event/dispatcher_impl.cc:171:3 (uds_integration_test+0x2ab73fe)
#5 Envoy::Server::WorkerImpl::threadRoutine(Envoy::Server::GuardDog&) /proc/self/cwd/source/server/worker_impl.cc:100:16 (uds_integration_test+0x1530da1)
#6 Envoy::Server::WorkerImpl::start(Envoy::Server::GuardDog&)::$_3::operator()() const /proc/self/cwd/source/server/worker_impl.cc:73:72 (uds_integration_test+0x1532bd4)
#7 std::_Function_handler<void (), Envoy::Server::WorkerImpl::start(Envoy::Server::GuardDog&)::$_3>::_M_invoke(std::_Any_data const&) /usr/lib/gcc/x86_64-linux-gnu/7.4.0/../../../../include/c++/7.4.0/bits/std_function.h:316:2 (uds_integration_test+0x153296a)
#8 std::function<void ()>::operator()() const /usr/lib/gcc/x86_64-linux-gnu/7.4.0/../../../../include/c++/7.4.0/bits/std_function.h:706:14 (uds_integration_test+0x1258bbe)
#9 Envoy::Thread::ThreadImplPosix::ThreadImplPosix(std::function<void ()>)::$_0::operator()(void*) const /proc/self/cwd/source/common/common/posix/thread_impl.cc:38:35 (uds_integration_test+0x3906b08)
#10 Envoy::Thread::ThreadImplPosix::ThreadImplPosix(std::function<void ()>)::$_0::__invoke(void*) /proc/self/cwd/source/common/common/posix/thread_impl.cc:37:33 (uds_integration_test+0x3906a98)
Previous write of size 1 at 0x0000045b3308 by thread T2 (mutexes: write M2352):
#0 event_del_nolock_ /build/tmp/_bazel_bazel/b570b5ccd0454dc9af9f65ab1833764d/execroot/envoy/external/com_github_libevent_libevent/event.c (uds_integration_test+0x38b03d1)
#1 event_process_active_single_queue /build/tmp/_bazel_bazel/b570b5ccd0454dc9af9f65ab1833764d/execroot/envoy/external/com_github_libevent_libevent/event.c:1608:5 (uds_integration_test+0x38b9d31)
#2 event_process_active /build/tmp/_bazel_bazel/b570b5ccd0454dc9af9f65ab1833764d/execroot/envoy/external/com_github_libevent_libevent/event.c:1738:9 (uds_integration_test+0x38b3f92)
#3 event_base_loop /build/tmp/_bazel_bazel/b570b5ccd0454dc9af9f65ab1833764d/execroot/envoy/external/com_github_libevent_libevent/event.c:1961 (uds_integration_test+0x38b3f92)
#4 Envoy::Event::DispatcherImpl::run(Envoy::Event::Dispatcher::RunType) /proc/self/cwd/source/common/event/dispatcher_impl.cc:171:3 (uds_integration_test+0x2ab73fe)
#5 Envoy::Server::InstanceImpl::run() /proc/self/cwd/source/server/server.cc:475:16 (uds_integration_test+0x140d0f2)
#6 Envoy::IntegrationTestServerImpl::createAndRunEnvoyServer(Envoy::OptionsImpl&, Envoy::Event::TimeSystem&, std::shared_ptr<Envoy::Network::Address::Instance const>, Envoy::TestHooks&, Envoy::Thread::BasicLockable&, Envoy::Server::ComponentFactory&, std::unique_ptr<Envoy::Runtime::RandomGenerator, std::default_delete<Envoy::Runtime::RandomGenerator> >&&) /proc/self/cwd/test/integration/server.cc:176:10 (uds_integration_test+0x133be94)
#7 Envoy::IntegrationTestServer::threadRoutine(Envoy::Network::Address::IpVersion, bool) /proc/self/cwd/test/integration/server.cc:152:3 (uds_integration_test+0x133ba6c)
#8 Envoy::IntegrationTestServer::start(Envoy::Network::Address::IpVersion, std::function<void ()>, bool, bool)::$_0::operator()() const /proc/self/cwd/test/integration/server.cc:72:50 (uds_integration_test+0x133d0de)
#9 std::_Function_handler<void (), Envoy::IntegrationTestServer::start(Envoy::Network::Address::IpVersion, std::function<void ()>, bool, bool)::$_0>::_M_invoke(std::_Any_data const&) /usr/lib/gcc/x86_64-linux-gnu/7.4.0/../../../../include/c++/7.4.0/bits/std_function.h:316:2 (uds_integration_test+0x133ce4a)
#10 std::function<void ()>::operator()() const /usr/lib/gcc/x86_64-linux-gnu/7.4.0/../../../../include/c++/7.4.0/bits/std_function.h:706:14 (uds_integration_test+0x1258bbe)
#11 Envoy::Thread::ThreadImplPosix::ThreadImplPosix(std::function<void ()>)::$_0::operator()(void*) const /proc/self/cwd/source/common/common/posix/thread_impl.cc:38:35 (uds_integration_test+0x3906b08)
#12 Envoy::Thread::ThreadImplPosix::ThreadImplPosix(std::function<void ()>)::$_0::__invoke(void*) /proc/self/cwd/source/common/common/posix/thread_impl.cc:37:33 (uds_integration_test+0x3906a98)
Location is global 'event_debug_mode_too_late' of size 1 at 0x0000045b3308 (uds_integration_test+0x0000045b3308)
Mutex M2486 (0x7b0c00026430) created at:
#0 pthread_mutex_init <null> (uds_integration_test+0x10ec5e3)
#1 evthread_posix_lock_alloc /build/tmp/_bazel_bazel/b570b5ccd0454dc9af9f65ab1833764d/execroot/envoy/external/com_github_libevent_libevent/evthread_pthread.c:53:6 (uds_integration_test+0x38c744b)
#2 event_base_new_with_config /build/tmp/_bazel_bazel/b570b5ccd0454dc9af9f65ab1833764d/execroot/envoy/external/com_github_libevent_libevent/event.c:682:3 (uds_integration_test+0x38ae6c7)
#3 event_base_new /build/tmp/_bazel_bazel/b570b5ccd0454dc9af9f65ab1833764d/execroot/envoy/external/com_github_libevent_libevent/event.c:485:10 (uds_integration_test+0x38ae8d5)
#4 Envoy::Event::DispatcherImpl::DispatcherImpl(std::unique_ptr<Envoy::Buffer::WatermarkFactory, std::default_delete<Envoy::Buffer::WatermarkFactory> >&&, Envoy::Api::Api&, Envoy::Event::TimeSystem&) /proc/self/cwd/source/common/event/dispatcher_impl.cc:37:61 (uds_integration_test+0x2ab46aa)
#5 Envoy::Event::DispatcherImpl::DispatcherImpl(Envoy::Api::Api&, Envoy::Event::TimeSystem&) /proc/self/cwd/source/common/event/dispatcher_impl.cc:30:7 (uds_integration_test+0x2ab4341)
Reactions are currently unavailable