firebase-ios-sdk icon indicating copy to clipboard operation
firebase-ios-sdk copied to clipboard

App crashed on data insert & delete in firestore

Open sspogra opened this issue 2 years ago • 3 comments

[REQUIRED] Step 1: Describe your environment

  • Xcode version:13.3.1
  • Firebase SDK version:9.2.0
  • Installation method: CocoaPods
  • Firebase Component: (Auth, Core, Database, Firestore, Messaging, Storage)
  • Target platform(s): iOS

[REQUIRED] Step 2: Describe the problem

Crashed: com.google.firebase.firestore
0  FirebaseFirestore              0xd13b0 firebase::firestore::local::LevelDbTransaction::Commit() + 124
1  FirebaseFirestore              0xc7968 firebase::firestore::local::LevelDbPersistence::RunInternal(absl::lts_20211102::string_view, std::__1::function<void ()>) + 160
2  FirebaseFirestore              0xdd7a8 firebase::firestore::local::LocalStore::WriteLocally(std::__1::vector<firebase::firestore::model::Mutation, std::__1::allocator<firebase::firestore::model::Mutation> >&&) + 260
3  FirebaseFirestore              0x138ba8 firebase::firestore::core::SyncEngine::WriteMutations(std::__1::vector<firebase::firestore::model::Mutation, std::__1::allocator<firebase::firestore::model::Mutation> >&&, std::__1::function<void (firebase::firestore::util::Status)>) + 92
4  FirebaseFirestore              0x6ec30 std::__1::__function::__func<firebase::firestore::core::FirestoreClient::WriteMutations(std::__1::vector<firebase::firestore::model::Mutation, std::__1::allocator<firebase::firestore::model::Mutation> >&&, 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<firebase::firestore::model::Mutation> >&&, std::__1::function<void (firebase::firestore::util::Status)>)::$_15>, void ()>::operator()() + 152
5  FirebaseFirestore              0x9354 firebase::firestore::util::AsyncQueue::ExecuteBlocking(std::__1::function<void ()> const&) + 68
6  FirebaseFirestore              0x145da8 firebase::firestore::util::Task::ExecuteAndRelease() + 184
7  libdispatch.dylib              0x64094 _dispatch_client_callout + 16
8  libdispatch.dylib              0xa73c _dispatch_lane_serial_drain$VARIANT$mp + 644
9  libdispatch.dylib              0xb1f4 _dispatch_lane_invoke$VARIANT$mp + 408
10 libdispatch.dylib              0x14ec8 _dispatch_workloop_worker_thread + 632
11 libsystem_pthread.dylib        0x1e10 _pthread_wqthread + 284
12 libsystem_pthread.dylib        0x193c start_wqthread + 8

Steps to reproduce:

App crashed when data insert & delete at the same time on a firestore collection. data size approx 50 entries.

Relevant Code:

        self.firestore.collection("Users")
            .document(String(userId!))
            .collection("company")
            .whereField("type", isEqualTo: "private")
            .getDocuments { (snapshot, error) in
                if error != nil {
                    callback(false, error)
                    return
                }
                
                if snapshot == nil || snapshot!.documents.isEmpty{
                    callback(true, nil)
                    return
                }
                
                var batch = self.firestore.batch()
                
                for (index, snap) in  snapshot!.documents.enumerated() {
                    batch.deleteDocument(snap.reference)
                    
                    if (index > 0) && ((index % 499)  == 0) {
                        batch.commit()
                        batch = self.firestore.batch()
                    }
                }
                
                batch.commit() { err in
                    if let err = err {
                        callback(false, err)
                        
                    } else {
                        callback(true, nil)
                    }
                }
            }


var newbatch = self.firestore.batch()
                
                for (index, model) in  list.enumerated() {
                    let data = model.toJSON()
                    let ref = self.firestore.collection("Users")
                        .document(String(userId!))
                        .collection("company")
                        .document(String(model.companyId))
                    
                    newbatch.setData(data, forDocument: ref, merge: true)
                    
                    if (index > 0) && ((index % 499)  == 0) {
                        batch.commit()
                        newbatch = self.firestore.batch()
                    }
                }
                
      newbatch.commit(completion: callback)

sspogra avatar Jun 30 '22 06:06 sspogra

I found a few problems with this issue:

  • I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.
  • This issue does not seem to follow the issue template. Make sure you provide all the required information.

google-oss-bot avatar Jun 30 '22 06:06 google-oss-bot

Sorry for the late reply, @sspogra. Is it possible for you to provide a sample runnable app that reproduces the issue?

rizafran avatar Jul 04 '22 16:07 rizafran

@rizafran I already added the sample code. Unable to provide sample application.

sspogra avatar Jul 05 '22 07:07 sspogra

FYI the fix is included in 9.5.0, released Aug 23, 2022.

dconeybe avatar Aug 25 '22 05:08 dconeybe

@dconeybe Thanks for the update

sspogra avatar Aug 25 '22 06:08 sspogra