-
Notifications
You must be signed in to change notification settings - Fork 11.1k
Data race in GRPCCall.m #15368
Copy link
Copy link
Closed
Description
What version of gRPC and what language are you using?
Objective-C.
What operating system (Linux, Windows, …) and version?
MacOS High Sierra 10.13.3
What runtime / compiler are you using (e.g. python version or version of gcc)
XCode 9.2
Issue details
We have recently started running our tests in iOS Firestore SDK under Thread Sanitizer. While running integration tests, TSan reports the following issue:
WARNING: ThreadSanitizer: data race (pid=77261)
Write of size 8 at 0x7b2800038d38 by thread T3 (mutexes: write M624728316330546296):
* #0 -[GRPCCall finishWithError:] GRPCCall.m:196 (GRPCClient:x86_64+0x42d5)
#1 -[GRPCCall maybeFinishWithError:] GRPCCall.m:244 (GRPCClient:x86_64+0x4b48)
#2 __22-[GRPCCall invokeCall]_block_invoke.156 GRPCCall.m:460 (GRPCClient:x86_64+0x8c59)
#3 __36-[GRPCOpRecvStatus initWithHandler:]_block_invoke GRPCWrappedCall.m:214 (GRPCClient:x86_64+0x1627a)
#4 -[GRPCOperation finish] GRPCWrappedCall.m:46 (GRPCClient:x86_64+0x135f6)
#5 __57-[GRPCWrappedCall startBatchWithOperations:errorHandler:]_block_invoke GRPCWrappedCall.m:293 (GRPCClient:x86_64+0x1769c)
#6 __27-[GRPCCompletionQueue init]_block_invoke_2 GRPCCompletionQueue.m:62 (GRPCClient:x86_64+0xd33e)
#7 __tsan::invoke_and_release_block(void*) <null>:2134816 (libclang_rt.tsan_iossim_dynamic.dylib:x86_64+0x6342b)
#8 _dispatch_client_callout <null>:2134816 (libdispatch.dylib:x86_64+0x31b9)
Previous read of size 8 at 0x7b2800038d38 by thread T1:
* #0 -[GRPCCall startNextRead] GRPCCall.m:273 (GRPCClient:x86_64+0x523f)
#1 __25-[GRPCCall startNextRead]_block_invoke_3 GRPCCall.m:309 (GRPCClient:x86_64+0x5a3e)
#2 __57-[GRXConcurrentWriteable enqueueValue:completionHandler:]_block_invoke GRXConcurrentWriteable.m:60 (RxLibrary:x86_64+0x31ef)
#3 __tsan::invoke_and_release_block(void*) <null>:2134816 (libclang_rt.tsan_iossim_dynamic.dylib:x86_64+0x6342b)
#4 _dispatch_client_callout <null>:2134816 (libdispatch.dylib:x86_64+0x31b9)
Issue is caused by frames marked with "*".
Location is heap block of size 160 at 0x7b2800038cc0 allocated by thread T14:
#0 calloc <null>:2134832 (libclang_rt.tsan_iossim_dynamic.dylib:x86_64+0x46812)
#1 class_createInstance <null>:2134832 (libobjc.A.dylib:x86_64+0xf011)
#2 -[FSTStream resumeStartWithToken:] <null>:2134832 (Firestore_Example_iOS:x86_64+0x1003becb5)
#3 invocation function for block in -[FSTStream startWithDelegate:]::$_0::operator()(firebase::firestore::util::StatusOr<firebase::firestore::auth::Token>) const <null>:2134832 (Firestore_Example_iOS:x86_64+0x1003cc6fa)
#4 -[FSTDispatchQueue dispatchAsyncAllowingSameQueue:]::$_2::operator()() const <null>:2134832 (Firestore_Example_iOS:x86_64+0x10024f003)
#5 void std::__1::__invoke_void_return_wrapper<void>::__call<-[FSTDispatchQueue dispatchAsyncAllowingSameQueue:]::$_2&>(-[FSTDispatchQueue dispatchAsyncAllowingSameQueue:]::$_2&&&) <null>:2134832 (Firestore_Example_iOS:x86_64+0x10024ef80)
#6 std::__1::__function::__func<-[FSTDispatchQueue dispatchAsyncAllowingSameQueue:]::$_2, std::__1::allocator<-[FSTDispatchQueue dispatchAsyncAllowingSameQueue:]::$_2>, void ()>::operator()() <null>:2134832 (Firestore_Example_iOS:x86_64+0x10024eb3c)
#7 std::__1::function<void ()>::operator()() const <null>:2134832 (Firestore_Example_iOS:x86_64+0x10015837c)
#8 firebase::firestore::util::AsyncQueue::ExecuteBlocking(std::__1::function<void ()> const&) <null>:2134832 (Firestore_Example_iOS:x86_64+0x1001581bd)
#9 firebase::firestore::util::AsyncQueue::Wrap(std::__1::function<void ()> const&)::$_0::operator()() const <null>:2134832 (Firestore_Example_iOS:x86_64+0x10015ca5f)
#10 void std::__1::__invoke_void_return_wrapper<void>::__call<firebase::firestore::util::AsyncQueue::Wrap(std::__1::function<void ()> const&)::$_0&>(firebase::firestore::util::AsyncQueue::Wrap(std::__1::function<void ()> const&)::$_0&&&) <null>:2134832 (Firestore_Example_iOS:x86_64+0x10015c9f0)
#11 std::__1::__function::__func<firebase::firestore::util::AsyncQueue::Wrap(std::__1::function<void ()> const&)::$_0, std::__1::allocator<firebase::firestore::util::AsyncQueue::Wrap(std::__1::function<void ()> const&)::$_0>, void ()>::operator()() <null>:2134832 (Firestore_Example_iOS:x86_64+0x10015c47c)
#12 std::__1::function<void ()>::operator()() const <null>:2134832 (Firestore_Example_iOS:x86_64+0x10015837c)
#13 firebase::firestore::util::internal::DispatchAsync(NSObject<OS_dispatch_queue>*, std::__1::function<void ()>&&)::$_0::operator()(void*) const <null>:2134832 (Firestore_Example_iOS:x86_64+0x100179f9c)
#14 firebase::firestore::util::internal::DispatchAsync(NSObject<OS_dispatch_queue>*, std::__1::function<void ()>&&)::$_0::__invoke(void*) <null>:2134832 (Firestore_Example_iOS:x86_64+0x100179f38)
#15 __tsan::dispatch_callback_wrap(void*) <null>:2134832 (libclang_rt.tsan_iossim_dynamic.dylib:x86_64+0x63571)
#16 _dispatch_client_callout <null>:2134832 (libdispatch.dylib:x86_64+0x31b9)
Mutex M624728316330546296 is already destroyed.
Thread T3 (tid=26723385, running) is a GCD worker thread
Thread T1 (tid=26723378, running) is a GCD worker thread
Thread T14 (tid=26723404, running) is a GCD worker thread
SUMMARY: ThreadSanitizer: data race GRPCCall.m:196 in -[GRPCCall finishWithError:]
Upon a glance, it appears to be a legitimate issue in GRPC code because the read of _state in startNextRead is not synchronized.
Reactions are currently unavailable