This repository was archived by the owner on Aug 8, 2023. It is now read-only.
Repository navigation
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
Hangs in Actor tests #6387
Copy link
Copy link
Closed
Description
We've seen a few CI failures due to timeouts in Actor tests. I ran mbgl-test --gtest_filter=Actor.* in a loop and reproduced a hang in Actor.NonConcurrentMailbox with the following stack traces:
Thread 1
#0 0x00007fff97d6910a in __semwait_signal ()
#1 0x00007fff98c4d787 in pthread_join ()
#2 0x00007fff8f853e95 in std::__1::thread::join() ()
#3 0x0000000108c57681 in mbgl::ThreadPool::~ThreadPool() at /Users/john/Development/mapbox-gl-native/src/mbgl/actor/thread_pool.cpp:38
#4 0x0000000108c577a5 in mbgl::ThreadPool::~ThreadPool() at /Users/john/Development/mapbox-gl-native/src/mbgl/actor/thread_pool.cpp:33
#5 0x00000001086b2e7c in Actor_NonConcurrentMailbox_Test::TestBody() at /Users/john/Development/mapbox-gl-native/test/actor/actor.cpp:139
#6 0x00000001091023e3 in void testing::internal::HandleSehExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) ()
#7 0x00000001090ed367 in void testing::internal::HandleExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) ()
#8 0x00000001090bcfd5 in testing::Test::Run() ()
#9 0x00000001090be51b in testing::TestInfo::Run() ()
#10 0x00000001090bf1b7 in testing::TestCase::Run() ()
#11 0x00000001090cd993 in testing::internal::UnitTestImpl::RunAllTests() ()
#12 0x00000001091062a3 in bool testing::internal::HandleSehExceptionsInMethodIfSupported<testing::internal::UnitTestImpl, bool>(testing::internal::UnitTestImpl*, bool (testing::internal::UnitTestImpl::*)(), char const*) ()
#13 0x00000001090efa47 in bool testing::internal::HandleExceptionsInMethodIfSupported<testing::internal::UnitTestImpl, bool>(testing::internal::UnitTestImpl*, bool (testing::internal::UnitTestImpl::*)(), char const*) ()
#14 0x00000001090cd590 in testing::UnitTest::Run() ()
#15 0x00000001088093d1 in RUN_ALL_TESTS() at /Users/john/Development/mapbox-gl-native/mason_packages/osx-x86_64/gtest/1.7.0/include/gtest/gtest.h:20058
#16 0x00000001088091b6 in mbgl::runTests(int, char**) at /Users/john/Development/mapbox-gl-native/test/src/mbgl/test/test.cpp:14
#17 0x00000001087fabdf in main at /Users/john/Development/mapbox-gl-native/test/src/main.cpp:19
#18 0x00007fff9c22f5ad in start ()
#19 0x00007fff9c22f5ad in start ()
Thread 3
#0 0x00007fff97d68db6 in __psynch_cvwait ()
#1 0x00007fff98c4c728 in _pthread_cond_wait ()
#2 0x00007fff8f81568f in std::__1::condition_variable::wait(std::__1::unique_lock<std::__1::mutex>&) ()
#3 0x0000000108c58881 in _ZNSt3__118condition_variable4waitIZZN4mbgl10ThreadPoolC1EmENK3$_0clEvEUlvE_EEvRNS_11unique_lockINS_5mutexEEET_ at /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/__mutex_base:344
#4 0x0000000108c58512 in mbgl::ThreadPool::ThreadPool(unsigned long)::$_0::operator()() const at /Users/john/Development/mapbox-gl-native/src/mbgl/actor/thread_pool.cpp:13
#5 0x0000000108c58249 in std::__1::__invoke<mbgl::ThreadPool::ThreadPool(unsigned long)::$_0>(decltype(std::__1::forward<mbgl::ThreadPool::ThreadPool(unsigned long)::$_0>(fp)(std::__1::forward<>(fp0))), mbgl::ThreadPool::ThreadPool(unsigned long)::$_0&&) [inlined] at /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/__functional_base:416
#6 0x0000000108c5823d in _ZNSt3__116__thread_executeIZN4mbgl10ThreadPoolC1EmE3$_0JEJEEEvRNS_5tupleIJT_DpT0_EEENS_15__tuple_indicesIJXspT1_EEEE [inlined] at /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/thread:337
#7 0x0000000108c5822d in std::__1::__thread_proxy<std::__1::tuple<mbgl::ThreadPool::ThreadPool(unsigned long)::$_0> >(void*, void*) at /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/thread:347
#8 0x00007fff98c4b99d in _pthread_body ()
#9 0x00007fff98c4b91a in _pthread_start ()
#10 0x00007fff98c49351 in thread_start ()
So somehow the thread pool thread is waiting on the condition variable, even though the main thread has set terminate to true and called notify_all.
Metadata
Metadata
Assignees
Labels
No labels
Activity
jfirebaugh commentedon Sep 20, 2016
cv.wait(lock, pred)is equivalent towhile (!pred()) { cv.wait(lock); }.~ThreadPooldidn't obtain the mutex before settingterminate. SoThreadPoolis subject to the following race condition:while (queue.empty() && !terminate)terminate = true;cv.notify_all();cv.wait(lock);I changed
~ThreadPoolto obtain the mutex before settingterminate, and could no longer replicate the hang.tmpsantos commentedon Sep 20, 2016
Seem that too.