google / glog

C++ implementation of the Google logging module
http://google.github.io/glog/
BSD 3-Clause "New" or "Revised" License
7.11k stars 2.07k forks source link

Glog crashes iOS app #741

Closed alexdmiller closed 3 years ago

alexdmiller commented 3 years ago

I'm building an iOS app that uses React Native and Google Media Pipe. My understanding is that both of these dependencies use glog. I'm getting a crash when I try to call into Google Media Pipe, and this sparse StackOverflow thread implies the problem is with two dependencies that are both using glog at the same time.

Is there any way to avoid this crash?

#0  0x00000001d2491334 in __pthread_kill ()
#1  0x00000001efedda9c in pthread_kill ()
#2  0x00000001ad728b90 in abort ()
#3  0x0000000102d1ae5c in glog_internal_namespace_::Mutex::Lock() at /Users/miller/Projects/openrdt-internal/OpenRDTCV/ios/Pods/glog/src/base/mutex.h:250
#4  0x000000010568913c in glog_internal_namespace_::MutexLock::MutexLock(glog_internal_namespace_::Mutex*) ()
#5  0x00000001056889f8 in glog_internal_namespace_::MutexLock::MutexLock(glog_internal_namespace_::Mutex*) ()
#6  0x0000000105688be4 in google::InitVLOG3__(int**, int*, char const*, int) ()
#7  0x0000000105565b38 in mediapipe::ValidatedGraphConfig::TopologicalSortNodes() ()
#8  0x0000000105563aa0 in mediapipe::ValidatedGraphConfig::Initialize(mediapipe::CalculatorGraphConfig const&, mediapipe::GraphRegistry const*, mediapipe::GraphServiceManager const*) ()
#9  0x0000000105353b70 in mediapipe::CalculatorGraph::Initialize(mediapipe::CalculatorGraphConfig const&, std::__1::map<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, mediapipe::Packet, std::__1::less<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::allocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const, mediapipe::Packet> > > const&) ()
#10 0x000000010534f0fc in mediapipe::CalculatorGraph::Initialize(mediapipe::CalculatorGraphConfig const&) ()
#11 0x0000000104e52148 in -[MPPGraph performStart] ()
#12 0x0000000104e52030 in -[MPPGraph startWithError:] ()
#13 0x0000000104e49bd8 in -[RDTInterpreter loadPipeline:] ()
#14 0x00000001028fd800 in RDTInterpretationModule.loadModel(_:resolver:rejecter:) at /Users/miller/Projects/openrdt-internal/OpenRDTCV/ios/OpenRDTCV/RDTInterpretationModule.swift:53
#15 0x00000001028fdb14 in @objc RDTInterpretationModule.loadModel(_:resolver:rejecter:) ()
#16 0x00000001a437f774 in __invoking___ ()
#17 0x00000001a4252d44 in -[NSInvocation invoke] ()
#18 0x00000001a4253348 in -[NSInvocation invokeWithTarget:] ()
#19 0x0000000102a8a0f8 in -[RCTModuleMethod invokeWithBridge:module:arguments:] at /Users/miller/Projects/openrdt-internal/OpenRDTCV/node_modules/react-native/React/Base/RCTModuleMethod.mm:584
#20 0x0000000102a8d43c in facebook::react::invokeInner(RCTBridge*, RCTModuleData*, unsigned int, folly::dynamic const&) at /Users/miller/Projects/openrdt-internal/OpenRDTCV/node_modules/react-native/React/CxxModule/RCTNativeModule.mm:114
#21 0x0000000102a8d01c in facebook::react::RCTNativeModule::invoke(unsigned int, folly::dynamic&&, int)::$_0::operator()() const at /Users/miller/Projects/openrdt-internal/OpenRDTCV/node_modules/react-native/React/CxxModule/RCTNativeModule.mm:75
#22 0x0000000102a8cf90 in invocation function for block in facebook::react::RCTNativeModule::invoke(unsigned int, folly::dynamic&&, int) at /Users/miller/Projects/openrdt-internal/OpenRDTCV/node_modules/react-native/React/CxxModule/RCTNativeModule.mm:67
#23 0x00000001081ec0b4 in _dispatch_call_block_and_release ()
#24 0x00000001081edde0 in _dispatch_client_callout ()
#25 0x00000001081f5ef0 in _dispatch_lane_serial_drain ()
#26 0x00000001081f6d14 in _dispatch_lane_invoke ()
#27 0x0000000108203a50 in _dispatch_workloop_worker_thread ()
#28 0x00000001efede7a4 in _pthread_wqthread ()
alexdmiller commented 3 years ago

I found that this issue describes the exact issue I'm having:

https://issueexplorer.com/issue/facebook/react-native/32256

sergiud commented 3 years ago

Related to #692. Unless you can provide a reproducer, not much can be done.

alexdmiller commented 3 years ago

That issue that I linked to has steps to reproduce. See the repository here: https://github.com/swittk/react-native-mediapipe-facemesh

And the steps:

  1. Run the example project in https://github.com/swittk/react-native-mediapipe-facemesh at example/ios
  2. Tap on Try alloc (This tries to allocate the class from the framework)
  3. Encounter SIGABRT from Mutex::Lock as described above.
  4. (optional) remove the abort() call and example app runs normally.
sergiud commented 3 years ago

I'm very well aware of the description but that won't cut it. You need to provide a minimal reproducer (in C++) which the example project does not even seem to use.

alexdmiller commented 3 years ago

Okay. A minimal reproduction is unfortunately a very high cost request considering the fact that I'm not even using glog myself. I'll open tickets on React Native and Google Media Pipe in the hopes that this is an error in their code rather than glog itself.

sergiud commented 3 years ago

Yes. You probably want to also check whether glog is compiled as shared library (not static). Otherwise you might be hitting undefined behavior caused by the initialization order of static variables in glog.

sergiud commented 3 years ago

I'll close the issue for the time being. Feel free to comment or reopen if there are new insights.