firebase / firebase-android-sdk

Firebase Android SDK
https://firebase.google.com
Apache License 2.0
2.27k stars 574 forks source link

With a large amount of pending deletes, newly added snapshot listeners stop being called #6381

Open sjudd opened 6 days ago

sjudd commented 6 days ago

[READ] Step 1: Are you in the right place?

Issues filed here should be about bugs in the code in this repository. If you have a general question, need help debugging, or fall into some other category use one of these other channels:

[REQUIRED] Step 2: Describe your environment

Android Studio Koala | 2024.1.1 Patch 1 Build #AI-241.18034.62.2411.12071903, built on July 10, 2024 Runtime version: 17.0.11+0-17.0.11b1207.24-11852314 aarch64 VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o. macOS 14.1 GC: G1 Young Generation, G1 Old Generation Memory: 8192M Cores: 12 Metal Rendering is ON Registry: debugger.new.tool.window.layout=true ide.experimental.ui=true Non-Bundled Plugins: de.santiv.fastscrolling (1.2) IdeaVIM (2.16.0)

[REQUIRED] Step 3: Describe the problem

With a large number of pending deletes, if I remove and add a few listeners (symmetrically), eventually newly added listeners are never notified of changes until I kill and restart the app.

I do not see this with a smaller number of documents (~50) added and removed in the same pattern.

Steps to reproduce:

I'm able to reproduce this reliably by following the steps listed here https://github.com/firebase/firebase-ios-sdk/issues/13883. I open the app, add a listener, then add 2500 documents and then delete them via the admin sdk as described. While firestore is processing the deletes on the client, I switch between two screens where one observes firestore and the other doesn't. Usually the first or second time I do this, I stop receiving updates in the newly added listeners. I've confirmed with logging that the listener is added.

I have two listeners, the first queries a collection, the second uses the output from the first query to observe a second collection. I've observed that even the first query with no other dependencies does not receive updates even though it is registered.

Relevant Code:

google-oss-bot commented 6 days ago

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

MarkDuckworth commented 4 days ago

@sjudd,

I switch between two screens where one observes firestore and the other doesn't.

When you switch between screens, are you removing and re-adding the listener?

ListenerRegistration registration = collection.addSnapshotListener(...);

// on switch to different screen
registration.remove();

// on switch back to screen using the listener, re-add the listener
registration = collection.addSnapshotListener(...);

I stop receiving updates in the newly added listeners

Are you stating that the listener will not produce any more snapshots for that collection? If your server app then adds a new document to the collection, is a new snapshot raised?

I think some code to demonstrate what your app is doing would be helpful. An MCVE would likely help us resolve the issue faster.

sjudd commented 4 days ago

Yes, going from screen A -> B, the listener is removed. Then going from B -> A, the listener is added again. It's at this point that the listener seems to stop receiving snapshots. If I add or delete new items in the collection no new snapshot is received.

I do wonder if this is just another symptom of Firestore being overloaded by https://github.com/firebase/firebase-ios-sdk/issues/13883. I've reported this issue here because I could only reproduce it on Android, not on iOS. I did not try waiting for the several minutes required for all of the deletes to be processed.

I've provided the listener example in the other issue, as well as the code used to add and remove documents.

MarkDuckworth commented 3 days ago

@sjudd, having logs from the SDK may also be useful in this case. Or we can try to focus on the iOS issue you reported first.

You can enable logging for the SDK with the instructions here: https://gist.github.com/katowulf/0475fb7a5907ed757f687aab6ed15878

To securely share a log, one way is to submit a firebase support case and attach the generate log in a file. Please reference internal bug b/373388444, so the team can route the log to the correct place. Thanks!