C++ helloworld greeter_client data races

126 views
Skip to first unread message

Zhiying Liang

unread,
Jun 17, 2022, 10:29:18 PM6/17/22
to grp...@googlegroups.com
Hello,

At first, we didn't build grpc-c++ with TSAN. When we ran greeter_server and greeter_client in the cpp/helloworld example, TSAN complained about data races for both server and client. Even though we build grpc c++ with bazel with tsan option, greeter_client still reports data races (greeter_server runs fine without any data races).

We  use the following command to build grpc c++ with bazel.
bazel build --subcommands --config tsan :all
 
 We build greeter_server and greeter_client with commands below.

bazel build --subcommands --config tsan //examples/cpp/helloworld:greeter_server

bazel build --subcommands --config tsan //examples/cpp/helloworld:greeter_client 

We run greeter_server and greeter_client with commands below.

bazel run --subcommands --config tsan //examples/cpp/helloworld:greeter_server

bazel run --subcommands --config tsan //examples/cpp/helloworld:greeter_client  

Here is the TSAN data race from greeter_client.

==================

WARNING: ThreadSanitizer: data race (pid=32094)

  Atomic write of size 4 at 0x7fabaeaf0140 by main thread:

    #0 __tsan_atomic32_fetch_add <null> (greeter_client+0x48cfc9)

    #1 absl::lts_20211102::synchronization_internal::Waiter::Post() <null> (greeter_client+0x1501592)

    #2 AbslInternalPerThreadSemPost_lts_20211102 <null> (greeter_client+0x15000c0)

    #3 absl::lts_20211102::synchronization_internal::PerThreadSem::Post(absl::lts_20211102::base_internal::ThreadIdentity*) <null> (greeter_client+0x14fac68)

    #4 absl::lts_20211102::Mutex::IncrementSynchSem(absl::lts_20211102::Mutex*, absl::lts_20211102::base_internal::PerThreadSynch*) <null> (greeter_client+0x14db7cc)

    #5 absl::lts_20211102::Mutex::Wakeup(absl::lts_20211102::base_internal::PerThreadSynch*) <null> (greeter_client+0x14de4fd)

    #6 absl::lts_20211102::Mutex::UnlockSlow(absl::lts_20211102::SynchWaitParams*) <null> (greeter_client+0x14e6ad2)

    #7 absl::lts_20211102::Mutex::Unlock() <null> (greeter_client+0x14ee6d3)

    #8 gpr_mu_unlock <null> (greeter_client+0x10cae0d)

    #9 grpc_core::Executor::Enqueue(grpc_closure*, grpc_error*, bool) <null> (greeter_client+0x108f457)

    #10 grpc_core::(anonymous namespace)::default_enqueue_short(grpc_closure*, grpc_error*) <null> (greeter_client+0x108ff70)

    #11 grpc_core::Executor::Run(grpc_closure*, grpc_error*, grpc_core::ExecutorType, grpc_core::ExecutorJobType) <null> (greeter_client+0x108f9b9)

    #12 on_writable(void*, grpc_error*) <null> (greeter_client+0xfe81db)

    #13 exec_ctx_run(grpc_closure*) <null> (greeter_client+0x1090577)

    #14 grpc_core::ExecCtx::Flush() <null> (greeter_client+0x1090277)

    #15 pollset_work(grpc_pollset*, grpc_pollset_worker**, grpc_core::Timestamp) <null> (greeter_client+0x1028ec2)

    #16 pollset_work(grpc_pollset*, grpc_pollset_worker**, grpc_core::Timestamp) <null> (greeter_client+0xfc5f35)

    #17 grpc_pollset_work(grpc_pollset*, grpc_pollset_worker**, grpc_core::Timestamp) <null> (greeter_client+0xfcf8b5)

    #18 cq_pluck(grpc_completion_queue*, void*, gpr_timespec, void*) <null> (greeter_client+0xf91ee3)

    #19 grpc_completion_queue_pluck <null> (greeter_client+0xf8ddc0)

    #20 grpc::CoreCodegen::grpc_completion_queue_pluck(grpc_completion_queue*, void*, gpr_timespec, void*) <null> (greeter_client+0x4e2572)

    #21 grpc::CompletionQueue::Pluck(grpc::internal::CompletionQueueTag*) <null> (greeter_client+0x11840fe)

    #22 grpc::internal::BlockingUnaryCallImpl<google::protobuf::MessageLite, google::protobuf::MessageLite>::BlockingUnaryCallImpl(grpc::ChannelInterface*, grpc::internal::RpcMethod const&, grpc::ClientContext*, google::protobuf::MessageLite const&, google::protobuf::MessageLite*) <null> (greeter_client+0x118346c)

    #23 grpc::Status grpc::internal::BlockingUnaryCall<helloworld::HelloRequest, helloworld::HelloReply, google::protobuf::MessageLite, google::protobuf::MessageLite>(grpc::ChannelInterface*, grpc::internal::RpcMethod const&, grpc::ClientContext*, helloworld::HelloRequest const&, helloworld::HelloReply*) <null> (greeter_client+0x117f376)

    #24 helloworld::Greeter::Stub::SayHello(grpc::ClientContext*, helloworld::HelloRequest const&, helloworld::HelloReply*) <null> (greeter_client+0x117de2b)

    #25 GreeterClient::SayHello(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) <null> (greeter_client+0x4cfa17)

    #26 main <null> (greeter_client+0x4cf31d)


  Previous write of size 8 at 0x7fabaeaf0140 by thread T1:

    #0 mmap <null> (greeter_client+0x47117a)

    #1 absl::lts_20211102::base_internal::DoAllocWithArena(unsigned long, absl::lts_20211102::base_internal::LowLevelAlloc::Arena*) <null> (greeter_client+0x1523d16)

    #2 absl::lts_20211102::base_internal::LowLevelAlloc::Alloc(unsigned long) <null> (greeter_client+0x159a8d8)

    #3 absl::lts_20211102::synchronization_internal::NewThreadIdentity() <null> (greeter_client+0x14ff5f9)

    #4 absl::lts_20211102::synchronization_internal::CreateThreadIdentity() <null> (greeter_client+0x14ff4d5)

    #5 absl::lts_20211102::synchronization_internal::GetOrCreateCurrentThreadIdentity() <null> (greeter_client+0x14fba06)

    #6 absl::lts_20211102::Synch_GetPerThread() <null> (greeter_client+0x14db955)

    #7 absl::lts_20211102::Synch_GetPerThreadAnnotated(absl::lts_20211102::Mutex*) <null> (greeter_client+0x14e2804)

    #8 absl::lts_20211102::CondVar::WaitCommon(absl::lts_20211102::Mutex*, absl::lts_20211102::synchronization_internal::KernelTimeout) <null> (greeter_client+0x14f3ab5)

    #9 absl::lts_20211102::CondVar::Wait(absl::lts_20211102::Mutex*) <null> (greeter_client+0x14f4032)

    #10 gpr_cv_wait <null> (greeter_client+0x10cb019)

    #11 grpc_core::Executor::ThreadMain(void*) <null> (greeter_client+0x108e89f)

    #12 grpc_core::(anonymous namespace)::ThreadInternalsPosix::ThreadInternalsPosix(char const*, void (*)(void*), void*, bool*, grpc_core::Thread::Options const&)::'lambda'(void*)::operator()(void*) const <null> (greeter_client+0x10b8cae)

    #13 grpc_core::(anonymous namespace)::ThreadInternalsPosix::ThreadInternalsPosix(char const*, void (*)(void*), void*, bool*, grpc_core::Thread::Options const&)::'lambda'(void*)::__invoke(void*) <null> (greeter_client+0x10b8aa8)


  Thread T1 'default-executo' (tid=32320, running) created by main thread at:

    #0 pthread_create <null> (greeter_client+0x4420ab)

    #1 grpc_core::(anonymous namespace)::ThreadInternalsPosix::ThreadInternalsPosix(char const*, void (*)(void*), void*, bool*, grpc_core::Thread::Options const&) <null> (greeter_client+0x10b860e)

    #2 grpc_core::Thread::Thread(char const*, void (*)(void*), void*, bool*, grpc_core::Thread::Options const&) <null> (greeter_client+0x10b7ee6)

    #3 grpc_core::Executor::SetThreading(bool) <null> (greeter_client+0x108da47)

    #4 grpc_core::Executor::Init() <null> (greeter_client+0x108d4ad)

    #5 grpc_core::Executor::InitAll() <null> (greeter_client+0x108f84a)

    #6 grpc_iomgr_init() <null> (greeter_client+0xfc8dbf)

    #7 grpc_init <null> (greeter_client+0x4ee7e0)

    #8 grpc::internal::GrpcLibrary::init() <null> (greeter_client+0x4d5314)

    #9 grpc::GrpcLibraryCodegen::GrpcLibraryCodegen(bool) <null> (greeter_client+0x4da5b5)

    #10 grpc::ChannelCredentials::ChannelCredentials() <null> (greeter_client+0x4db694)

    #11 grpc::(anonymous namespace)::InsecureChannelCredentialsImpl::InsecureChannelCredentialsImpl() <null> (greeter_client+0x4d0f9f)

    #12 grpc::InsecureChannelCredentials() <null> (greeter_client+0x4d0efe)

    #13 main <null> (greeter_client+0x4cf271)


SUMMARY: ThreadSanitizer: data race (/home/ubuntu/.cache/bazel/_bazel_ubuntu/df42107a157c46139b2bdf13d539ef7e/execroot/com_github_grpc_grpc/bazel-out/k8-fastbuild/bin/examples/cpp/helloworld/greeter_client+0x48cfc9) in __tsan_atomic32_fetch_add

==================


gRPC version: v1.45.0
system version: Ubuntu, 20.04 LTS

Any ideas or suggestions would be greatly appreciated!

Thanks,
Zhiying

Mark D. Roth

unread,
Jun 22, 2022, 1:55:31 PM6/22/22
to Zhiying Liang, grpc. io
This looks like a bug.  Please file an issue on https://github.com/grpc/grpc.  Thanks!

--
You received this message because you are subscribed to the Google Groups "grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email to grpc-io+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/grpc-io/CAJJ7bD8aMFzQLdDeiEfsz%2BwJKO9BC%2B_AKnjcUFh1QaHv-MvVbg%40mail.gmail.com.


--
Mark D. Roth <ro...@google.com>
Software Engineer
Google, Inc.
Reply all
Reply to author
Forward
0 new messages