Failed to get document because the client is offline
See original GitHub issue[REQUIRED] Step 2: Describe your environment
- Android Studio version: _____ 4.1.3
- Firebase Component: _____ Firestore
- Component version: _____ BOM 26.3.0
[REQUIRED] Step 3: Describe the problem
When network is not available, library is crashing.
Fatal Exception: q.i.c.t.l: Failed to get document because the client is offline.
at com.google.firebase.firestore.DocumentReference.lambda$getViaSnapshotListener$1(DocumentReference.java:6)
at com.google.firebase.firestore.DocumentReference$$Lambda$2.onEvent(DocumentReference.java:6)
at com.google.firebase.firestore.DocumentReference.lambda$addSnapshotListenerInternal$2(DocumentReference.java:16)
at com.google.firebase.firestore.DocumentReference$$Lambda$3.onEvent(DocumentReference.java:16)
at com.google.firebase.firestore.core.AsyncEventListener.lambda$onEvent$0(AsyncEventListener.java:1)
at com.google.firebase.firestore.core.AsyncEventListener$$Lambda$1.run(AsyncEventListener.java:1)
at com.google.firebase.firestore.util.Executors$$Lambda$1.execute(Executors.java)
at com.google.firebase.firestore.core.AsyncEventListener.onEvent(AsyncEventListener.java:2)
at com.google.firebase.firestore.core.QueryListener.raiseInitialEvent(QueryListener.java:14)
at com.google.firebase.firestore.core.QueryListener.onViewSnapshot(QueryListener.java:15)
at com.google.firebase.firestore.core.EventManager.onViewSnapshots(EventManager.java:4)
at com.google.firebase.firestore.core.SyncEngine.listen(SyncEngine.java:31)
at com.google.firebase.firestore.core.EventManager.addQueryListener(EventManager.java:31)
at com.google.firebase.firestore.core.FirestoreClient.lambda$listen$6(FirestoreClient.java:31)
at com.google.firebase.firestore.core.FirestoreClient$$Lambda$6.run(FirestoreClient.java:31)
at com.google.firebase.firestore.util.AsyncQueue.lambda$enqueue$2(AsyncQueue.java:1)
at com.google.firebase.firestore.util.AsyncQueue$$Lambda$2.call(AsyncQueue.java:1)
at com.google.firebase.firestore.util.AsyncQueue$SynchronizedShutdownAwareExecutor.lambda$executeAndReportResult$1(AsyncQueue.java:1)
at com.google.firebase.firestore.util.AsyncQueue$SynchronizedShutdownAwareExecutor$$Lambda$2.run(AsyncQueue.java:1)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:462)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:301)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at com.google.firebase.firestore.util.AsyncQueue$SynchronizedShutdownAwareExecutor$DelayedStartFactory.run(AsyncQueue.java:15)
at java.lang.Thread.run(Thread.java:919)
DocumentReference class has even a TODO in a place exception is thrown: // TODO: Reconsider how to raise missing documents when offline. // If we’re online and the document doesn’t exist then we set the result // of the Task with a document with document.exists set to false. If we’re // offline however, we set the Exception on the Task. Two options: // // 1) Cache the negative response from the server so we can deliver that // even when you’re offline. // 2) Actually set the Exception of the Task if the document doesn’t // exist when you are offline.
Steps to reproduce:
It’s really hard to reproduce. Common root cause of the issue is problem with a network or DNS resolution.
Relevant Code:
Simple read of firestore snapshot e.g.
internal suspend fun readDocument(
id1: String,
id2: String
) = firestore.collection("somepath").document(id1).collection("collectionpath")
.document(id2)
.get()
.await()
.takeIf { it.exists() }
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:12 (6 by maintainers)
Top GitHub Comments
@dconeybe Thanks for the detailed explanation of this issue. We’re facing the same exception in our app since 2018 😮
We added
try ... catch
around allget().await()
calls however this exception still occurs foraddSnapshotListener()
. The stack trace is as follows:Shouldn’t a snapshot listener only fire when there is actual data to be fetched? In which scenario can this exception happen inside a snapshot listener and how can it be handled on our side?
Firestore version 22.1.2.
Update: Sorry, I misread the stack trace.
getViaSnapshotListener()
is used internally byget()
only.No, thank you! Now that we added
try...catch
there should be an improvement in stability.