firebase-ios-sdk: Crash in grpc_library.h line 42 under iOS and iPadOS 14
Step 1: Describe your environment
- Xcode version: 13.2.1
- Firebase SDK version: 8.13.0
- Installation method:
CocoaPods - Firebase Component: Firestore
- Target platform(s):
iOS
Step 2: Describe the problem
Steps to reproduce:
Haven’t been able to reproduce myself yet. The crash is spiking in our latest app release and only affects devices running iOS and iPadOS 14.
I’ve tried reproducing on a physical device running iOS 14 with Address Sanitizer and Undefined Behaviour Sanitizer enabled, alas without success.
The logs we get from Crashlytics:
Crashed: com.google.firebase.firestore EXC_BAD_ACCESS KERN_INVALID_ADDRESS 0x0000000000000000
Crashed: com.google.firebase.firestore
0 FirebaseFirestore 0x2d514 grpc::GrpcLibraryCodegen::GrpcLibraryCodegen(bool) + 42 (grpc_library.h:42)
1 FirebaseFirestore 0x2d3d8 grpc_impl::CompletionQueue::CompletionQueue(grpc_completion_queue_attributes const&) + 247 (completion_queue_impl.h:247)
2 FirebaseFirestore 0x2b100 firebase::firestore::remote::Datastore::Datastore(firebase::firestore::core::DatabaseInfo const&, std::__1::shared_ptr<firebase::firestore::util::AsyncQueue> const&, std::__1::shared_ptr<firebase::firestore::credentials::CredentialsProvider<firebase::firestore::credentials::AuthToken, firebase::firestore::credentials::User> >, std::__1::shared_ptr<firebase::firestore::credentials::CredentialsProvider<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >, firebase::firestore::remote::ConnectivityMonitor*, firebase::firestore::remote::FirebaseMetadataProvider*) + 104 (datastore.cc:104)
3 FirebaseFirestore 0x61750 firebase::firestore::core::FirestoreClient::Initialize(firebase::firestore::credentials::User const&, firebase::firestore::api::Settings const&) + 3237 (memory:3237)
4 FirebaseFirestore 0x6f4c firebase::firestore::util::AsyncQueue::ExecuteBlocking(std::__1::function<void ()> const&) + 993 (atomic:993)
5 FirebaseFirestore 0x12aefc firebase::firestore::util::Task::ExecuteAndRelease() + 1871 (functional:1871)
6 libdispatch.dylib 0x61280 _dispatch_client_callout + 16
7 libdispatch.dylib 0x9dcc _dispatch_lane_serial_drain$VARIANT$mp + 612
8 libdispatch.dylib 0xa8a8 _dispatch_lane_invoke$VARIANT$mp + 424
9 libdispatch.dylib 0x14338 _dispatch_workloop_worker_thread + 712
10 libsystem_pthread.dylib 0xa5a4 _pthread_wqthread + 272
11 libsystem_pthread.dylib 0xd874 start_wqthread + 8
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 3
- Comments: 62 (22 by maintainers)
I am able to confirm that releasing another build without any changes except for a version bump resolves the issue,.
We don’t have crashes from Firebase SDK, but we have similar crashes from the gRPC library we integrated with our App. The crash only happens for some iOS 14 users. We didn’t bump gRPC between releases, this is what our stack trace looks like.
We even tried to release a previous build (which is not crashing) with just a version bump, the strange thing is the build with only a version bump started crashing as well with the same stack trace. This leads me to think, there might be something changed from the Apple side when recompiling the app from the bitcode.
Xcode 13.3 was released on 14th Mar 2022. The timeline aligns, but I am not sure if it could be the cause. When I compare the install size of 2 builds with only version difference. The second one has 1mb less.
The gRPC lib is integrated with the iOS app as an XCFramework via SPM. The iOS project is built using Xcode 13.2.1 as well.
Here is the patch: https://gist.github.com/dconeybe/31892c1d5c6b1c7d366947a46ee0207a
This patch potentially fixes an issue with the static initialization of
g_glipin grpc. But since I cannot reproduce the crash I cannot test it out for myself.Here is how you would use it:
pod updateorpod installon your project; this will create thePodsdirectory.patch -Np0 -i grpc.patch.txtAfter running the “patch” command you should see output like this, which indicates success:
Now build your project in xcode and publish it to the app store. Make sure that the build you publish to the app store has this patch applied to grpc. Once published, see if the crash reports continue or cease.
@ondrejkorol One more question… are you by any chance using Firestore in the initialization of a global variable? Because that could explain why
g_glipis null because then the Firestore code could be running beforeg_glipis initialized.To see if multiple copies of the library are linked into the app, the Xcode console will show warnings at launch time.
@ondrejkorol Sorry, I made a mistake on the Xcode version. The working version for us is Xcode 13.2.1.
Just install the app via MDM on an iOS 14 device to reproduce the crash.
To anyone experiencing this bug, please upgrade to at least v8.15.0 of the Firebase iOS SDK (preferably the latest, which is v9.0.0 at the time of writing). Please report back if this upgrade fixes the crash. If it does not fix the crash, then please provide updated stack traces.
Please do not report crashes against older versions of the Firebase iOS SDK. Namely, if you see
completion_queue_impl.hin your stack trace, then you are using an older version of the Firebase iOS SDK, as that file was deleted from grpc.The reason for this request is that the Firebase iOS SDK upgraded its grpc dependency from 1.28.0 to 1.44.0 in Firebase iOS SDK v8.15.0. This upgrade may even fix the crash.
We have had the exact same issue and now released a new build built with Xcode 13.3.1 and Firestore version 9 but we are still seeing the crash. ( before grpc_library.h line 43 now grpc_library.h line 45) Anyone else ?
@JanGorman Thanks for reporting this. This looks like an issue in the underlying library and likely the same as https://github.com/grpc/grpc/issues/24850. I will ping someone from the GRPC team to gain some traction.