lday0321 commented on issue #1687:
URL:
https://github.com/apache/incubator-brpc/issues/1687#issuecomment-1024202843
感谢回复! 移除这里的pthread_mutex_lock/pthread_mutex_unlock,combiner.h:310这里的TSAN
warning的确没了。但还是些其他的报错,例如:
```bash
WARNING: ThreadSanitizer: data race (pid=12180)
Write of size 4 at 0x7b4800020080 by main thread (mutexes: write M924):
#0 butil::BoundedQueue<unsigned long>::push(unsigned long const&)
/v/brpc/incubator-brpc/src/butil/containers/bounded_queue.h:103:13
(tsan_test+0x31aee7)
#1 bthread::RemoteTaskQueue::push_locked(unsigned long)
/v/brpc/incubator-brpc/src/bthread/remote_task_queue.h:69 (tsan_test+0x31aee7)
#2 bthread::TaskGroup::ready_to_run_remote(unsigned long, bool)
/v/brpc/incubator-brpc/src/bthread/task_group.cpp:669 (tsan_test+0x31aee7)
#3 int bthread::TaskGroup::start_background<true>(unsigned long*,
bthread_attr_t const*, void* (*)(void*), void*)
/v/brpc/incubator-brpc/src/bthread/task_group.cpp:446:9 (tsan_test+0x31fa09)
#4 bthread::start_from_non_worker(unsigned long*, bthread_attr_t const*,
void* (*)(void*), void*) /v/brpc/incubator-brpc/src/bthread/bthread.cpp:144:35
(tsan_test+0x2f0411)
#5 bthread_start_background
/v/brpc/incubator-brpc/src/bthread/bthread.cpp:193 (tsan_test+0x2f0411)
#6 brpc::GlobalInitializeOrDieImpl()
/v/brpc/incubator-brpc/src/brpc/global.cpp:612:5 (tsan_test+0x393922)
#7 pthread_once <null> (tsan_test+0x1bf41f)
#8 brpc::GlobalInitializeOrDie()
/v/brpc/incubator-brpc/src/brpc/global.cpp:617:9 (tsan_test+0x391b44)
#9 brpc::Server::InitializeOnce()
/v/brpc/incubator-brpc/src/brpc/server.cpp:610:5 (tsan_test+0x279436)
#10 brpc::Server::StartInternal(in_addr const&, brpc::PortRange const&,
brpc::ServerOptions const*) /v/brpc/incubator-brpc/src/brpc/server.cpp:712:9
(tsan_test+0x2796bc)
#11 brpc::Server::Start(butil::EndPoint const&, brpc::ServerOptions
const*) /v/brpc/incubator-brpc/src/brpc/server.cpp:1062:12 (tsan_test+0x27deef)
#12 my::(anonymous namespace)::MyTest_TSAN_Check_brpc_Test::TestBody()
/v/tsan_demo/tsan_test.cc:29:19 (tsan_test+0x23067c)
#13 void
testing::internal::HandleExceptionsInMethodIfSupported<testing::Test,
void>(testing::Test*, void (testing::Test::*)(), char const*) <null>
(tsan_test+0x264c1c)
#14 main /v/tsan_demo/tsan_test.cc:46:10 (tsan_test+0x22fea8)
Previous read of size 4 at 0x7b4800020080 by thread T5:
#0 butil::BoundedQueue<unsigned long>::empty() const
/v/brpc/incubator-brpc/src/butil/containers/bounded_queue.h:260:34
(tsan_test+0x30f002)
#1 bthread::RemoteTaskQueue::pop(unsigned long*)
/v/brpc/incubator-brpc/src/bthread/remote_task_queue.h:52 (tsan_test+0x30f002)
#2 bthread::TaskControl::steal_task(unsigned long*, unsigned long*,
unsigned long) /v/brpc/incubator-brpc/src/bthread/task_control.cpp:354
(tsan_test+0x30f002)
#3 bthread::TaskGroup::steal_task(unsigned long*)
/v/brpc/incubator-brpc/src/bthread/task_group.h:221:26 (tsan_test+0x32017f)
#4 bthread::TaskGroup::wait_task(unsigned long*)
/v/brpc/incubator-brpc/src/bthread/task_group.cpp:125:13 (tsan_test+0x31b5cd)
#5 bthread::TaskGroup::run_main_task()
/v/brpc/incubator-brpc/src/bthread/task_group.cpp:152 (tsan_test+0x31b5cd)
#6 bthread::TaskControl::worker_thread(void*)
/v/brpc/incubator-brpc/src/bthread/task_control.cpp:76:8 (tsan_test+0x30c7f3)
Location is heap block of size 384 at 0x7b480001ff80 allocated by thread
T4:
#0 operator new(unsigned long, std::nothrow_t const&) <null>
(tsan_test+0x22ee53)
#1 bthread::TaskControl::create_group()
/v/brpc/incubator-brpc/src/bthread/task_control.cpp:89:20 (tsan_test+0x30cb8d)
#2 bthread::TaskControl::worker_thread(void*)
/v/brpc/incubator-brpc/src/bthread/task_control.cpp:65:23 (tsan_test+0x30c66d)
Mutex M924 (0x7b4800020098) created at:
#0 pthread_mutex_init <null> (tsan_test+0x1bf03a)
#1 butil::Mutex::Mutex()
/v/brpc/incubator-brpc/src/butil/synchronization/lock.h:51:9
(tsan_test+0x31c007)
#2 bthread::RemoteTaskQueue::RemoteTaskQueue()
/v/brpc/incubator-brpc/src/bthread/remote_task_queue.h:38 (tsan_test+0x31c007)
#3 bthread::TaskGroup::TaskGroup(bthread::TaskControl*)
/v/brpc/incubator-brpc/src/bthread/task_group.cpp:176 (tsan_test+0x31c007)
#4 bthread::TaskControl::create_group()
/v/brpc/incubator-brpc/src/bthread/task_control.cpp:89:39 (tsan_test+0x30cba4)
#5 bthread::TaskControl::worker_thread(void*)
/v/brpc/incubator-brpc/src/bthread/task_control.cpp:65:23 (tsan_test+0x30c66d)
Thread T5 (tid=12186, running) created by main thread at:
#0 pthread_create <null> (tsan_test+0x1bec16)
#1 bthread::TaskControl::init(int)
/v/brpc/incubator-brpc/src/bthread/task_control.cpp:165:24 (tsan_test+0x30dc40)
#2 bthread::get_or_new_task_control()
/v/brpc/incubator-brpc/src/bthread/bthread.cpp:91:12 (tsan_test+0x2f1753)
#3 bthread::start_from_non_worker(unsigned long*, bthread_attr_t const*,
void* (*)(void*), void*) /v/brpc/incubator-brpc/src/bthread/bthread.cpp:128:22
(tsan_test+0x2f03d7)
#4 bthread_start_background
/v/brpc/incubator-brpc/src/bthread/bthread.cpp:193 (tsan_test+0x2f03d7)
#5 brpc::GlobalInitializeOrDieImpl()
/v/brpc/incubator-brpc/src/brpc/global.cpp:612:5 (tsan_test+0x393922)
#6 pthread_once <null> (tsan_test+0x1bf41f)
#7 brpc::GlobalInitializeOrDie()
/v/brpc/incubator-brpc/src/brpc/global.cpp:617:9 (tsan_test+0x391b44)
#8 brpc::Server::InitializeOnce()
/v/brpc/incubator-brpc/src/brpc/server.cpp:610:5 (tsan_test+0x279436)
#9 brpc::Server::StartInternal(in_addr const&, brpc::PortRange const&,
brpc::ServerOptions const*) /v/brpc/incubator-brpc/src/brpc/server.cpp:712:9
(tsan_test+0x2796bc)
#10 brpc::Server::Start(butil::EndPoint const&, brpc::ServerOptions
const*) /v/brpc/incubator-brpc/src/brpc/server.cpp:1062:12 (tsan_test+0x27deef)
#11 my::(anonymous namespace)::MyTest_TSAN_Check_brpc_Test::TestBody()
/v/tsan_demo/tsan_test.cc:29:19 (tsan_test+0x23067c)
#12 void
testing::internal::HandleExceptionsInMethodIfSupported<testing::Test,
void>(testing::Test*, void (testing::Test::*)(), char const*) <null>
(tsan_test+0x264c1c)
#13 main /v/tsan_demo/tsan_test.cc:46:10 (tsan_test+0x22fea8)
Thread T4 (tid=12185, running) created by main thread at:
#0 pthread_create <null> (tsan_test+0x1bec16)
#1 bthread::TaskControl::init(int)
/v/brpc/incubator-brpc/src/bthread/task_control.cpp:165:24 (tsan_test+0x30dc40)
#2 bthread::get_or_new_task_control()
/v/brpc/incubator-brpc/src/bthread/bthread.cpp:91:12 (tsan_test+0x2f1753)
#3 bthread::start_from_non_worker(unsigned long*, bthread_attr_t const*,
void* (*)(void*), void*) /v/brpc/incubator-brpc/src/bthread/bthread.cpp:128:22
(tsan_test+0x2f03d7)
#4 bthread_start_background
/v/brpc/incubator-brpc/src/bthread/bthread.cpp:193 (tsan_test+0x2f03d7)
#5 brpc::GlobalInitializeOrDieImpl()
/v/brpc/incubator-brpc/src/brpc/global.cpp:612:5 (tsan_test+0x393922)
#6 pthread_once <null> (tsan_test+0x1bf41f)
#7 brpc::GlobalInitializeOrDie()
/v/brpc/incubator-brpc/src/brpc/global.cpp:617:9 (tsan_test+0x391b44)
#8 brpc::Server::InitializeOnce()
/v/brpc/incubator-brpc/src/brpc/server.cpp:610:5 (tsan_test+0x279436)
#9 brpc::Server::StartInternal(in_addr const&, brpc::PortRange const&,
brpc::ServerOptions const*) /v/brpc/incubator-brpc/src/brpc/server.cpp:712:9
(tsan_test+0x2796bc)
#10 brpc::Server::Start(butil::EndPoint const&, brpc::ServerOptions
const*) /v/brpc/incubator-brpc/src/brpc/server.cpp:1062:12 (tsan_test+0x27deef)
#11 my::(anonymous namespace)::MyTest_TSAN_Check_brpc_Test::TestBody()
/v/tsan_demo/tsan_test.cc:29:19 (tsan_test+0x23067c)
#12 void
testing::internal::HandleExceptionsInMethodIfSupported<testing::Test,
void>(testing::Test*, void (testing::Test::*)(), char const*) <null>
(tsan_test+0x264c1c)
#13 main /v/tsan_demo/tsan_test.cc:46:10 (tsan_test+0x22fea8)
SUMMARY: ThreadSanitizer: data race
/v/brpc/incubator-brpc/src/butil/containers/bounded_queue.h:103:13 in
butil::BoundedQueue<unsigned long>::push(unsigned long const&)
```
这里我感觉像是brpc有意为之?

我在另一个报在timer_thread.cpp的data race:
```bash
WARNING: ThreadSanitizer: data race (pid=12180)
Write of size 8 at 0x7b5c00001650 by thread T7:
#0 bthread::TimerThread::Bucket::schedule(void (*)(void*), void*,
timespec const&) /v/brpc/incubator-brpc/src/bthread/timer_thread.cpp:207:20
(tsan_test+0x323497)
#1 bthread::TimerThread::schedule(void (*)(void*), void*, timespec
const&) /v/brpc/incubator-brpc/src/bthread/timer_thread.cpp:226:10
(tsan_test+0x3235fa)
#2 bthread::TaskGroup::_add_sleep_event(void*)
/v/brpc/incubator-brpc/src/bthread/task_group.cpp:745:43 (tsan_test+0x31e62a)
#3 bthread::TaskGroup::sched_to(bthread::TaskGroup**,
bthread::TaskMeta*) /v/brpc/incubator-brpc/src/bthread/task_group.cpp:623:9
(tsan_test+0x31def5)
#4 bthread::TaskGroup::sched_to(bthread::TaskGroup**, unsigned long)
/v/brpc/incubator-brpc/src/bthread/task_group_inl.h:78:5 (tsan_test+0x2f4954)
#5 bthread::TaskGroup::sched(bthread::TaskGroup**)
/v/brpc/incubator-brpc/src/bthread/task_group.cpp:561:5 (tsan_test+0x31ea8c)
#6 bthread::TaskGroup::usleep(bthread::TaskGroup**, unsigned long)
/v/brpc/incubator-brpc/src/bthread/task_group.cpp:790 (tsan_test+0x31ea8c)
#7 bthread_usleep /v/brpc/incubator-brpc/src/bthread/bthread.cpp:364:16
(tsan_test+0x2f0e98)
#8 brpc::GlobalUpdate(void*)
/v/brpc/incubator-brpc/src/brpc/global.cpp:234:17 (tsan_test+0x3944ed)
#9 bthread::TaskGroup::task_runner(long)
/v/brpc/incubator-brpc/src/bthread/task_group.cpp:295:29 (tsan_test+0x31bb3e)
#10 bthread_make_fcontext <null> (tsan_test+0x2f74c0)
#11 bthread::TaskGroup::sched_to(bthread::TaskGroup**, unsigned long)
/v/brpc/incubator-brpc/src/bthread/task_group_inl.h:78:5 (tsan_test+0x2f4954)
#12 bthread::TaskGroup::run_main_task()
/v/brpc/incubator-brpc/src/bthread/task_group.cpp:153:9 (tsan_test+0x31b5e6)
#13 bthread::TaskControl::worker_thread(void*)
/v/brpc/incubator-brpc/src/bthread/task_control.cpp:76:8 (tsan_test+0x30c7f3)
Previous read of size 8 at 0x7b5c00001650 by thread T2:
#0 bthread::TimerThread::Bucket::consume_tasks()
/v/brpc/incubator-brpc/src/bthread/timer_thread.cpp:169:9 (tsan_test+0x321e1c)
#1 bthread::TimerThread::run()
/v/brpc/incubator-brpc/src/bthread/timer_thread.cpp:354 (tsan_test+0x321e1c)
#2 bthread::TimerThread::run_this(void*)
/v/brpc/incubator-brpc/src/bthread/timer_thread.cpp:120:37 (tsan_test+0x321949)
Location is heap block of size 896 at 0x7b5c00001500 allocated by main
thread:
#0 operator new[](unsigned long, std::nothrow_t const&) <null>
(tsan_test+0x22eef3)
#1 bthread::TimerThread::start(bthread::TimerThreadOptions const*)
/v/brpc/incubator-brpc/src/bthread/timer_thread.cpp:154:16 (tsan_test+0x322e84)
#2 bthread::init_global_timer_thread()
/v/brpc/incubator-brpc/src/bthread/timer_thread.cpp:465:36 (tsan_test+0x323d1d)
#3 pthread_once <null> (tsan_test+0x1bf41f)
#4 bthread::get_or_create_global_timer_thread()
/v/brpc/incubator-brpc/src/bthread/timer_thread.cpp:474:5 (tsan_test+0x323b81)
#5 bthread::TaskControl::init(int)
/v/brpc/incubator-brpc/src/bthread/task_control.cpp:158:9 (tsan_test+0x30dae6)
#6 bthread::get_or_new_task_control()
/v/brpc/incubator-brpc/src/bthread/bthread.cpp:91:12 (tsan_test+0x2f1753)
#7 bthread::start_from_non_worker(unsigned long*, bthread_attr_t const*,
void* (*)(void*), void*) /v/brpc/incubator-brpc/src/bthread/bthread.cpp:128:22
(tsan_test+0x2f03d7)
#8 bthread_start_background
/v/brpc/incubator-brpc/src/bthread/bthread.cpp:193 (tsan_test+0x2f03d7)
#9 brpc::GlobalInitializeOrDieImpl()
/v/brpc/incubator-brpc/src/brpc/global.cpp:612:5 (tsan_test+0x393922)
#10 pthread_once <null> (tsan_test+0x1bf41f)
#11 brpc::GlobalInitializeOrDie()
/v/brpc/incubator-brpc/src/brpc/global.cpp:617:9 (tsan_test+0x391b44)
#12 brpc::Server::InitializeOnce()
/v/brpc/incubator-brpc/src/brpc/server.cpp:610:5 (tsan_test+0x279436)
#13 brpc::Server::StartInternal(in_addr const&, brpc::PortRange const&,
brpc::ServerOptions const*) /v/brpc/incubator-brpc/src/brpc/server.cpp:712:9
(tsan_test+0x2796bc)
#14 brpc::Server::Start(butil::EndPoint const&, brpc::ServerOptions
const*) /v/brpc/incubator-brpc/src/brpc/server.cpp:1062:12 (tsan_test+0x27deef)
#15 my::(anonymous namespace)::MyTest_TSAN_Check_brpc_Test::TestBody()
/v/tsan_demo/tsan_test.cc:29:19 (tsan_test+0x23067c)
#16 void
testing::internal::HandleExceptionsInMethodIfSupported<testing::Test,
void>(testing::Test*, void (testing::Test::*)(), char const*) <null>
(tsan_test+0x264c1c)
#17 main /v/tsan_demo/tsan_test.cc:46:10 (tsan_test+0x22fea8)
Thread T7 (tid=12188, running) created by main thread at:
#0 pthread_create <null> (tsan_test+0x1bec16)
#1 bthread::TaskControl::init(int)
/v/brpc/incubator-brpc/src/bthread/task_control.cpp:165:24 (tsan_test+0x30dc40)
#2 bthread::get_or_new_task_control()
/v/brpc/incubator-brpc/src/bthread/bthread.cpp:91:12 (tsan_test+0x2f1753)
#3 bthread::start_from_non_worker(unsigned long*, bthread_attr_t const*,
void* (*)(void*), void*) /v/brpc/incubator-brpc/src/bthread/bthread.cpp:128:22
(tsan_test+0x2f03d7)
#4 bthread_start_background
/v/brpc/incubator-brpc/src/bthread/bthread.cpp:193 (tsan_test+0x2f03d7)
#5 brpc::GlobalInitializeOrDieImpl()
/v/brpc/incubator-brpc/src/brpc/global.cpp:612:5 (tsan_test+0x393922)
#6 pthread_once <null> (tsan_test+0x1bf41f)
#7 brpc::GlobalInitializeOrDie()
/v/brpc/incubator-brpc/src/brpc/global.cpp:617:9 (tsan_test+0x391b44)
#8 brpc::Server::InitializeOnce()
/v/brpc/incubator-brpc/src/brpc/server.cpp:610:5 (tsan_test+0x279436)
#9 brpc::Server::StartInternal(in_addr const&, brpc::PortRange const&,
brpc::ServerOptions const*) /v/brpc/incubator-brpc/src/brpc/server.cpp:712:9
(tsan_test+0x2796bc)
#10 brpc::Server::Start(butil::EndPoint const&, brpc::ServerOptions
const*) /v/brpc/incubator-brpc/src/brpc/server.cpp:1062:12 (tsan_test+0x27deef)
#11 my::(anonymous namespace)::MyTest_TSAN_Check_brpc_Test::TestBody()
/v/tsan_demo/tsan_test.cc:29:19 (tsan_test+0x23067c)
#12 void
testing::internal::HandleExceptionsInMethodIfSupported<testing::Test,
void>(testing::Test*, void (testing::Test::*)(), char const*) <null>
(tsan_test+0x264c1c)
#13 main /v/tsan_demo/tsan_test.cc:46:10 (tsan_test+0x22fea8)
Thread T2 (tid=12183, running) created by main thread at:
#0 pthread_create <null> (tsan_test+0x1bec16)
#1 bthread::TimerThread::start(bthread::TimerThreadOptions const*)
/v/brpc/incubator-brpc/src/bthread/timer_thread.cpp:159:21 (tsan_test+0x32313f)
#2 bthread::init_global_timer_thread()
/v/brpc/incubator-brpc/src/bthread/timer_thread.cpp:465:36 (tsan_test+0x323d1d)
#3 pthread_once <null> (tsan_test+0x1bf41f)
#4 bthread::get_or_create_global_timer_thread()
/v/brpc/incubator-brpc/src/bthread/timer_thread.cpp:474:5 (tsan_test+0x323b81)
#5 bthread::TaskControl::init(int)
/v/brpc/incubator-brpc/src/bthread/task_control.cpp:158:9 (tsan_test+0x30dae6)
#6 bthread::get_or_new_task_control()
/v/brpc/incubator-brpc/src/bthread/bthread.cpp:91:12 (tsan_test+0x2f1753)
#7 bthread::start_from_non_worker(unsigned long*, bthread_attr_t const*,
void* (*)(void*), void*) /v/brpc/incubator-brpc/src/bthread/bthread.cpp:128:22
(tsan_test+0x2f03d7)
#8 bthread_start_background
/v/brpc/incubator-brpc/src/bthread/bthread.cpp:193 (tsan_test+0x2f03d7)
#9 brpc::GlobalInitializeOrDieImpl()
/v/brpc/incubator-brpc/src/brpc/global.cpp:612:5 (tsan_test+0x393922)
#10 pthread_once <null> (tsan_test+0x1bf41f)
#11 brpc::GlobalInitializeOrDie()
/v/brpc/incubator-brpc/src/brpc/global.cpp:617:9 (tsan_test+0x391b44)
#12 brpc::Server::InitializeOnce()
/v/brpc/incubator-brpc/src/brpc/server.cpp:610:5 (tsan_test+0x279436)
#13 brpc::Server::StartInternal(in_addr const&, brpc::PortRange const&,
brpc::ServerOptions const*) /v/brpc/incubator-brpc/src/brpc/server.cpp:712:9
(tsan_test+0x2796bc)
#14 brpc::Server::Start(butil::EndPoint const&, brpc::ServerOptions
const*) /v/brpc/incubator-brpc/src/brpc/server.cpp:1062:12 (tsan_test+0x27deef)
#15 my::(anonymous namespace)::MyTest_TSAN_Check_brpc_Test::TestBody()
/v/tsan_demo/tsan_test.cc:29:19 (tsan_test+0x23067c)
#16 void
testing::internal::HandleExceptionsInMethodIfSupported<testing::Test,
void>(testing::Test*, void (testing::Test::*)(), char const*) <null>
(tsan_test+0x264c1c)
#17 main /v/tsan_demo/tsan_test.cc:46:10 (tsan_test+0x22fea8)
SUMMARY: ThreadSanitizer: data race
/v/brpc/incubator-brpc/src/bthread/timer_thread.cpp:207:20 in
bthread::TimerThread::Bucket::schedule(void (*)(void*), void*, timespec const&)
```
中看到timer_thread.cpp:169,有一段注释说是为了减少一次mutex访问:

类似这类场景,似乎TSAN也无法正确识别。
完整的error msg见附件:
[tsan_error.log](https://github.com/apache/incubator-brpc/files/7958817/tsan_error.log)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]