firebase / firebase-ios-sdk

Firebase SDK for Apple App Development
https://firebase.google.com
Apache License 2.0
5.55k stars 1.45k forks source link

Firebase Query Crash, EXC_BAD_ACCESS (KERN_INVALID_ADDRESS) on App Startup (iOS) #11978

Closed philip511 closed 10 months ago

philip511 commented 10 months ago

Description

I am experiencing this crash on one specific line of code, in one specific method, within the first 2 seconds of the app openning.

This crash occurrs randomly on my users devices and never on mine so I cannot reproduce it. I just have what Firebase Crashlytics provides.


Some extra details about the code:

This query is run in ViewDidLoad on the first page the user sees when they open the app

This query is run in a background thread

This query is run concurrently with 6 other queries each on their own background thread

This crash only occurs in this specific query in this specific line

This crash usually occurs on the first iteration of FIRDocumentSnapshot but occasionally occurs after multiple iterations


Some solutions I've already tried:

I've tried allowing this query to finish before running any other queries

I've tried running this query last, after all other queries have finished

I've tried adding NULL checks to snapshot, doc, and doc.data

I've tried checking for an NSError

I've tried running it on the main thread


Crash occurs on this line when accessing doc.data

NSLog(@"Test %@", doc.data);


dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

   FIRFirestore *defaultFirestore = [FIRFirestore firestore];

   [[[[defaultFirestore collectionWithPath:@"Homes"] documentWithPath:homeID] collectionWithPath:collection] getDocumentsWithCompletion:^(FIRQuerySnapshot * _Nullable snapshot, NSError * _Nullable error) {

       if (error == nil) {

          for (FIRDocumentSnapshot *doc in snapshot.documents) {

             if (doc != nil) {        

                NSLog(@"Test %@", doc.data);

             }

          }

       }

   }];

});

Reproducing the issue

I am completely unable to reproduce this issue. I just have the information that Firebase Crashlytics provides

Firebase SDK Version

10.16.0

Xcode Version

15.0.1

Installation Method

CocoaPods

Firebase Product(s)

Firestore

Targeted Platforms

iOS

Relevant Log Output

Crashed: com.apple.main-thread
EXC_BAD_ACCESS KERN_INVALID_ADDRESS 0x0000000000000000

Crashed: com.apple.main-thread
0  FirebaseFirestore              0x8fe6c -[FSTUserDataWriter convertedValue:] + 280
1  FirebaseFirestore              0x8ff80 -[FSTUserDataWriter convertedObject:] + 120
2  FirebaseFirestore              0x8fed8 -[FSTUserDataWriter convertedValue:] + 388
3  FirebaseFirestore              0x59dd0 -[FIRDocumentSnapshot dataWithServerTimestampBehavior:] + 200
4  FirebaseFirestore              0x5a228 -[FIRQueryDocumentSnapshot dataWithServerTimestampBehavior:] + 44
5  FirebaseFirestore              0x5a184 -[FIRQueryDocumentSnapshot data] + 44
6  WeDivvy                        0x2a8e70 __125-[GetDataObject GetDataGetItemsInSpecificHome:collection:keyArray:currentViewController:crashlyticsString:completionHandler:]_block_invoke + 1849 (GetDataObject.m:1849)
7  FirebaseFirestore              0x87d2c -[FIRQuery wrapQuerySnapshotBlock:]::Converter::OnEvent(firebase::firestore::util::StatusOr<firebase::firestore::api::QuerySnapshot>) + 128
8  FirebaseFirestore              0x11ba98 firebase::firestore::api::Query::GetDocuments(firebase::firestore::api::Source, std::__1::unique_ptr<firebase::firestore::core::EventListener<firebase::firestore::api::QuerySnapshot>, std::__1::default_delete<firebase::firestore::core::EventListener<firebase::firestore::api::QuerySnapshot> > >&&)::ListenOnce::OnEvent(firebase::firestore::util::StatusOr<firebase::firestore::api::QuerySnapshot>) + 360
9  FirebaseFirestore              0x11bf84 firebase::firestore::api::Query::AddSnapshotListener(firebase::firestore::core::ListenOptions, std::__1::unique_ptr<firebase::firestore::core::EventListener<firebase::firestore::api::QuerySnapshot>, std::__1::default_delete<firebase::firestore::core::EventListener<firebase::firestore::api::QuerySnapshot> > >&&)::Converter::OnEvent(firebase::firestore::util::StatusOr<firebase::firestore::core::ViewSnapshot>) + 616
10 FirebaseFirestore              0x3defc void std::__1::__invoke_void_return_wrapper<void, true>::__call<firebase::firestore::core::AsyncEventListener<firebase::firestore::core::ViewSnapshot>::OnEvent(firebase::firestore::util::StatusOr<firebase::firestore::core::ViewSnapshot>)::'lambda'()&>(firebase::firestore::core::AsyncEventListener<firebase::firestore::core::ViewSnapshot>::OnEvent(firebase::firestore::util::StatusOr<firebase::firestore::core::ViewSnapshot>)::'lambda'()&) + 104
11 FirebaseFirestore              0x14f80c firebase::firestore::util::Task::ExecuteAndRelease() + 188
12 libdispatch.dylib              0x3fdc _dispatch_client_callout + 20
13 libdispatch.dylib              0x127f4 _dispatch_main_queue_drain + 928
14 libdispatch.dylib              0x12444 _dispatch_main_queue_callback_4CF + 44
15 CoreFoundation                 0x9a6f8 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 16
16 CoreFoundation                 0x7c058 __CFRunLoopRun + 2036
17 CoreFoundation                 0x80ed4 CFRunLoopRunSpecific + 612
18 GraphicsServices               0x1368 GSEventRunModal + 164
19 UIKitCore                      0x3a23d0 -[UIApplication _run] + 888
20 UIKitCore                      0x3a2034 UIApplicationMain + 340
21 WeDivvy                        0x35968 main + 18 (main.m:18)
22 ???                            0x1c7ecc960 (Missing)

If using Swift Package Manager, the project's Package.resolved

Expand Package.resolved snippet
```json Replace this line with the contents of your Package.resolved. ```

If using CocoaPods, the project's Podfile.lock

Expand Podfile.lock snippet
```yml # Uncomment the next line to define a global platform for your project platform :ios, '14.0' target 'WeDivvy' do # Comment the next line if you don't want to use dynamic frameworks use_frameworks! # Pods for WeDivvy post_install do |installer| installer.generated_projects.each do |project| project.targets.each do |target| target.build_configurations.each do |config| config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '14.0' end end end end ENV['SWIFT_VERSION'] = '5' pod 'Firebase/Core' pod 'Firebase/Crashlytics' pod 'Firebase/Database' pod 'Firebase/Analytics' pod 'Firebase/Auth' pod 'Firebase/Storage' pod 'Firebase/Messaging' pod 'Firebase/Firestore' pod 'Firebase/Functions' pod 'MRProgress' pod 'InstantSearch' pod 'InstantSearchClient' pod 'SDWebImage' pod 'Mixpanel' pod 'GoogleSignIn' end ```
google-oss-bot commented 10 months ago

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

paulb777 commented 10 months ago

Thanks for the report @philip511. Please share the Firebase version used in the app

philip511 commented 10 months ago

@paulb777 Sorry! I updated my post, SDK version 10.16.0

ehsannas commented 10 months ago

Thanks for reporting @philip511 . It'd be quite difficult to pinpoint the bug without a reproduction.

The stack trace suggests the issue to be related to converting a Firestore "Value" to an obj-c type. Would you be able to share the document content(s) that are being read? (feel free to obfuscate the content, but keep the types and also keep empty strings and nulls)

Thanks!

philip511 commented 10 months ago

Yea, I mean the document content isn't anything special. It's about 30ish keys. Mostly strings, maps, and arrays.

morganchen12 commented 10 months ago

@philip511 please share the document data anyway, redacted if necessary.

ehsannas commented 10 months ago

Closing as there's been no repro.