firebase / firebase-ios-sdk

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

App Crashed when update data on firestore in background. #9997

Open sspogra opened 2 years ago

sspogra commented 2 years ago

[REQUIRED] Step 1: Describe your environment

[REQUIRED] Step 2: Describe the problem

App Crashed on user location updated on firestore document when app is in background.

Crashed: com.google.firebase.firestore 0 libsystem_kernel.dylib 0x7b38 pthread_kill + 8 1 libsystem_pthread.dylib 0x73bc pthread_kill + 268 2 libsystem_c.dylib 0x20524 abort + 168 3 libsystem_malloc.dylib 0x1ca04 _malloc_put + 550 4 libsystem_malloc.dylib 0x1cc9c malloc_zone_error + 100 5 libsystem_malloc.dylib 0x170dc nanov2_allocate_from_block + 568 6 libsystem_malloc.dylib 0x16164 nanov2_allocate + 128 7 libsystem_malloc.dylib 0x16080 nanov2_malloc + 64 8 libsystem_malloc.dylib 0x6024 _malloc_zone_malloc + 156 9 libc++abi.dylib 0x138a0 operator new(unsigned long) + 32 10 FirebaseFirestore 0xdf74 firebase::firestore::model::MutableDocument::MutableDocument() + 52 (shared_ptr.h:52) 11 FirebaseFirestore 0x40d14 firebase::firestore::immutable::impl::FixedArray<std::1::pair<firebase::firestore::model::Document, firebase::firestore::util::Empty>>::FixedArray<std::1::pair<firebase::firestore::model::Document, firebase::firestore::util::Empty> const>(std::__1::pair<firebase::firestore::model::Document, firebase::firestore::util::Empty> const, std::1::pair<firebase::firestore::model::Document, firebase::firestore::util::Empty> const*) + 129 (array:129) 12 FirebaseFirestore 0x408a0 std::1::shared_ptr<firebase::firestore::immutable::impl::FixedArray<std::1::pair<firebase::firestore::model::Document, firebase::firestore::util::Empty>>> std::1::make_shared<firebase::firestore::immutable::impl::FixedArray<std::1::pair<firebase::firestore::model::Document, firebase::firestore::util::Empty>>, std::1::pair<firebase::firestore::model::Document, firebase::firestore::util::Empty> const, std::__1::pair<firebase::firestore::model::Document, firebase::firestore::util::Empty> const&, void>(std::1::pair<firebase::firestore::model::Document, firebase::firestore::util::Empty> const*&&, std::1::pair<firebase::firestore::model::Document, firebase::firestore::util::Empty> const*&) + 635 (shared_ptr.h:635) 13 FirebaseFirestore 0x3f1ec firebase::firestore::immutable::impl::ArraySortedMap<firebase::firestore::model::Document, firebase::firestore::util::Empty, firebase::firestore::model::DocumentComparator>::insert(firebase::firestore::model::Document const&, firebase::firestore::util::Empty const&) const + 589 (shared_ptr.h:589) 14 FirebaseFirestore 0x3ee04 firebase::firestore::immutable::SortedMap<firebase::firestore::model::Document, firebase::firestore::util::Empty, firebase::firestore::model::DocumentComparator>::insert(firebase::firestore::model::Document const&, firebase::firestore::util::Empty const&) const + 371 (sorted_map.h:371) 15 FirebaseFirestore 0x39a78 firebase::firestore::immutable::SortedSet<firebase::firestore::model::Document, firebase::firestore::model::DocumentComparator>::insert(firebase::firestore::model::Document const&) const + 51 (sorted_set.h:51) 16 FirebaseFirestore 0x396d4 firebase::firestore::model::DocumentSet::insert(absl::lts_20211102::optional const&) const + 137 (document_set.h:137) 17 FirebaseFirestore 0x149048 firebase::firestore::core::View::ComputeDocumentChanges(firebase::firestore::immutable::SortedMap<firebase::firestore::model::DocumentKey, firebase::firestore::model::Document, firebase::firestore::util::Comparator> const&, absl::lts_20211102::optional const&) const + 198 (view.cc:198) 18 FirebaseFirestore 0x1308c0 firebase::firestore::core::SyncEngine::EmitNewSnapshotsAndNotifyLocalStore(firebase::firestore::immutable::SortedMap<firebase::firestore::model::DocumentKey, firebase::firestore::model::Document, firebase::firestore::util::Comparator> const&, absl::lts_20211102::optional const&) + 475 (sync_engine.cc:475) 19 FirebaseFirestore 0x1303c4 firebase::firestore::core::SyncEngine::WriteMutations(std::1::vector<firebase::firestore::model::Mutation, std::1::allocator>&&, std::1::function<void (firebase::firestore::util::Status)>) + 212 (sync_engine.cc:212) 20 FirebaseFirestore 0x6a3f0 std::1::function::func<firebase::firestore::core::FirestoreClient::WriteMutations(std::1::vector<firebase::firestore::model::Mutation, std::1::allocator>&&, std::1::function<void (firebase::firestore::util::Status)>)::$_15, std::1::allocator<firebase::firestore::core::FirestoreClient::WriteMutations(std::1::vector<firebase::firestore::model::Mutation, std::1::allocator>&&, std::1::function<void (firebase::firestore::util::Status)>)::$_15>, void ()>::operator()() + 463 (function.h:463) 21 FirebaseFirestore 0x678c firebase::firestore::util::AsyncQueue::ExecuteBlocking(std::__1::function<void ()> const&) + 997 (atomic:997) 22 FirebaseFirestore 0x13d6e8 firebase::firestore::util::Task::ExecuteAndRelease() + 491 (function.h:491) 23 libdispatch.dylib 0x3a30 _dispatch_client_callout + 20 24 libdispatch.dylib 0xb124 _dispatch_lane_serial_drain + 668 25 libdispatch.dylib 0xbc80 _dispatch_lane_invoke + 392 26 libdispatch.dylib 0x16500 _dispatch_workloop_worker_thread + 648 27 libsystem_pthread.dylib 0x10bc _pthread_wqthread + 288 28 libsystem_pthread.dylib 0xe5c start_wqthread + 8


Steps to reproduce:

Updating user location in every minute in background and we are saving this location data in firestore document. App crashed randomly for few users.

Relevant Code:

func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
        let  updatedUserLocation = locations.last
        if updatedUserLocation == nil {
            return
        }

        let data = [
           "current_location": GeoPoint(latitude: updatedUserLocation?.coordinate.latitude ?? 0.0, longitude: updatedUserLocation?.coordinate.longitude ?? 0.0),
            "location_updated_at": Timestamp(date: Date())
        ]

        let path = "Users.\(String(11))"
        self.saveCrashlyticsLog(name: "updateUser", path: path, data: data)

         Firestore.firestore().collection("Users")
            .document(String(11))
            .setData(data, merge: true)
    }
google-oss-bot commented 2 years ago

I found a few problems with this issue:

sspogra commented 2 years ago

@rizafran
Another crash log for same code-

Crashed: com.google.GDTCORFlatFileStorage 0 libsystem_kernel.dylib 0x7b38 pthread_kill + 8 1 libsystem_pthread.dylib 0x73bc pthread_kill + 268 2 libsystem_c.dylib 0x20524 abort + 168 3 libsystem_malloc.dylib 0x1ca04 _malloc_put + 550 4 libsystem_malloc.dylib 0x1cc9c malloc_zone_error + 100 5 libsystem_malloc.dylib 0x170dc nanov2_allocate_from_block + 568 6 libsystem_malloc.dylib 0x16164 nanov2_allocate + 128 7 libsystem_malloc.dylib 0x16080 nanov2_malloc + 64 8 libsystem_malloc.dylib 0x6024 _malloc_zone_malloc + 156 9 CoreFoundation 0x3f408 CFStrAllocateMutableContents + 100 10 CoreFoundation 0x2ef48 CFStringChangeSizeMultiple + 656 11 CoreFoundation 0x29d20 CFStringAppend + 560 12 CoreFoundation 0x67fdc -[NSArray componentsJoinedByString:] + 288 13 GoogleDataTransport 0x1288c -[GDTCORFlatFileStorage eventComponentsFromFilename:] + 764 (GDTCORFlatFileStorage.m:764) 14 GoogleDataTransport 0x12124 80-[GDTCORFlatFileStorage pathsForTarget:eventIDs:qosTiers:mappingIDs:onComplete:]_block_invoke_2 + 710 (GDTCORFlatFileStorage.m:710) 15 libdispatch.dylib 0x1e6c _dispatch_call_block_and_release + 32 16 libdispatch.dylib 0x3a30 _dispatch_client_callout + 20 17 libdispatch.dylib 0xb124 _dispatch_lane_serial_drain + 668 18 libdispatch.dylib 0xbc80 _dispatch_lane_invoke + 392 19 libdispatch.dylib 0x16500 _dispatch_workloop_worker_thread + 648 20 libsystem_pthread.dylib 0x10bc _pthread_wqthread + 288 21 libsystem_pthread.dylib 0xe5c start_wqthread + 8

wu-hui commented 2 years ago

The firestore error here is similar to https://github.com/firebase/firebase-ios-sdk/issues/9995, i guess you cannot reliably reproduce this one?

sspogra commented 2 years ago

@wu-hui Unable to re-produce it locally but when app goes live it occurred again.