question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
svenjacobscommented, Apr 16, 2021

@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 all get().await() calls however this exception still occurs for addSnapshotListener(). The stack trace is as follows:

com.google.firebase.firestore.FirebaseFirestoreException: Failed to get document because the client is offline.
       at com.google.firebase.firestore.DocumentReference.lambda$getViaSnapshotListener$1(DocumentReference.java:331)
       at com.google.firebase.firestore.DocumentReference$$Lambda$2.onEvent(DocumentReference.java:8)
       at com.google.firebase.firestore.DocumentReference.lambda$addSnapshotListenerInternal$2(DocumentReference.java:504)
       at com.google.firebase.firestore.DocumentReference$$Lambda$3.onEvent(DocumentReference.java:16)
       at com.google.firebase.firestore.core.AsyncEventListener.lambda$onEvent$0(AsyncEventListener.java:42)
       at com.google.firebase.firestore.core.AsyncEventListener$$Lambda$1.run(AsyncEventListener.java:2)
       at com.google.firebase.firestore.util.Executors$$Lambda$1.execute(Executors.java)
       at com.google.firebase.firestore.core.AsyncEventListener.onEvent(AsyncEventListener.java:39)
       at com.google.firebase.firestore.core.QueryListener.raiseInitialEvent(QueryListener.java:176)
       at com.google.firebase.firestore.core.QueryListener.onViewSnapshot(QueryListener.java:95)
       at com.google.firebase.firestore.core.EventManager.addQueryListener(EventManager.java:97)
       at com.google.firebase.firestore.core.FirestoreClient.lambda$listen$6(FirestoreClient.java:160)
       at com.google.firebase.firestore.core.FirestoreClient$$Lambda$6.run(FirestoreClient.java:12)
       at com.google.firebase.firestore.util.AsyncQueue.lambda$enqueue$2(AsyncQueue.java:436)
       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:322)
       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:229)
       at java.lang.Thread.run(Thread.java:919)

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 by get() only.

0reactions
svenjacobscommented, Apr 18, 2021

@svenjacobs Do you still have an issue to discuss? If so, could you open a new issue and tag me?

No, thank you! Now that we added try...catch there should be an improvement in stability.

Read more comments on GitHub >

github_iconTop Results From Across the Web

firestore Failed to get document because the client is offline ...
Yes it's the normal behaviour to get an error with get on a collection if the service could not be reached (when online...
Read more >
Firebase Cloud Firestore throws "client is offline"
Auth, Realtime DB and Storage work perfectly fine. Failed to get document because the client is offline. Error. Is there something I can...
Read more >
Failed to get document because the client is offline.
W/Firestore(25403): This typically indicates that your device does not have a healthy Internet connection at the moment. The client will operate in offline...
Read more >
[code=unavailable]: Failed to get document because the client ...
The error I keep getting is: FirebaseError: [code=unavailable]: Failed to get document because the client is offline. I have no idea what I...
Read more >
"FirebaseError: failed to get document because the client is ...
I'm working on an Ionic-App with multiple tabs. When I run the app in the browser using ionic serve everything runs as it...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found