Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

App crashed on data insert & delete in firestore #9965

Closed
sspogra opened this issue Jun 30, 2022 · 5 comments · Fixed by #10101
Closed

App crashed on data insert & delete in firestore #9965

sspogra opened this issue Jun 30, 2022 · 5 comments · Fixed by #10101
Assignees

Comments

@sspogra
Copy link

sspogra commented Jun 30, 2022

[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)

@google-oss-bot
Copy link

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.

@sspogra sspogra changed the title Crashed: com.google.firebase.firestore EXC_BAD_ACCESS KERN_INVALID_ADDRESS 0x0000028034c90000 App crashed on data insert & delete in firestore Jun 30, 2022
@rizafran
Copy link
Contributor

rizafran commented Jul 4, 2022

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

@ehsannas ehsannas self-assigned this Jul 4, 2022
@sspogra
Copy link
Author

sspogra commented Jul 5, 2022

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

@dconeybe
Copy link
Contributor

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

@sspogra
Copy link
Author

sspogra commented Aug 25, 2022

@dconeybe Thanks for the update

@firebase firebase locked and limited conversation to collaborators Sep 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants