"the client is offline." but it's not the case
[REQUIRED] Describe your environment
- Operating System version: windows 10 (v21H2)
- Browser version: react-native 0.67.3
- Firebase SDK version: 9.6.7
- Firebase Product: database , firestore , auth
[REQUIRED] Describe the problem
I saw the #5836 and many others on Stack Overflow, i'm facing the same issue i recreated a few time test projects to try connect to Firestore but since i am using firebase v9 modular i can't access the database, same problem on my physical device (SM-A520F - 8.0.0) android 8 and on many emulators using android studio (Pixel, Pixel 2, Pixel 3, Pixel 4) different android version from 8 to 10.
the error is always the same :
ERROR [2022-02-27T23:03:53.595Z] @firebase/firestore: Firestore (9.6.7): Could not reach Cloud Firestore backend. Backend didn't respond within 10 seconds.
This typically indicates that your device does not have a healthy Internet connection at the moment. The client will operate in offline mode until it is able to successfully connect to the backend.
LOG [FirebaseError: Failed to get document because the client is offline.]
Steps to reproduce:
-
Create react app using
npx react-native init AppName -
Install firebase :
npm i firebase -
Go in App.js and try this :
Relevant Code:
//App.js
import React from 'react';
import {
Text,
View,
TouchableOpacity
} from 'react-native';
import { initializeApp } from 'firebase/app';
import { getFirestore, doc, getDoc } from "firebase/firestore";
const firebaseConfig = {
apiKey: "AIzaSyB-57*****************************",
authDomain: "***********.firebaseapp.com",
projectId: "***********",
storageBucket: "***********.appspot.com",
messagingSenderId: "28**********",
appId: "1:28*************************************",
measurementId: "G-5*********"
};
const app = initializeApp(firebaseConfig);
const Firestore = getFirestore(app)
const App = () => {
async function onPress() {
const my_doc = await getDoc(doc(Firestore, '/CollectionName/DocumentID'))
console.log(my_doc.data())
}
return (
<View>
<TouchableOpacity
onPress={onPress}
>
<Text>Press Here</Text>
</TouchableOpacity>
</View>
);
};
export default App;
when i press the Text i wait 10-12s and the console return me the error above, the exact same error on all my support, i have did all my test with the same PC, i will try on another asap.
I am stuck with this from a long time now and i don't understand the problem, i have a excellent connection (more than 100mb/s) when i do speedtest on my device or my emulators.
I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.
Although I am not sure what exactly it is, using Firestore JS SDK in React Native has always met with connection issues like this. While I will try to troubleshoot this, I think you might be better off to try https://github.com/invertase/react-native-firebase instead.
I think you might be better off to try https://github.com/invertase/react-native-firebase instead.
The advantage of v9 modular is the final size of the project is majorly reduced, if i use rn-firebase would i take advantage of the v9 like with the real firebase or not ?
https://github.com/invertase/react-native-firebase uses the Android or iOS SDK under the hood and not the Web SDK. There is currently no tree-shaking.
Can you invoke setLogLevel('debug') and share the logs?
This is what I am seeing:
LOG [2022-03-02T20:05:00.812Z] @firebase/firestore: Firestore (9.6.7): FirebaseAuthCredentialsProvider Auth not yet detected
LOG [2022-03-02T20:05:00.813Z] @firebase/firestore: Firestore (9.6.7): FirestoreClient Using default OnlineComponentProvider
LOG [2022-03-02T20:05:00.813Z] @firebase/firestore: Firestore (9.6.7): FirestoreClient Using default OfflineComponentProvider
LOG [2022-03-02T20:05:00.814Z] @firebase/firestore: Firestore (9.6.7): FirestoreClient Initializing OfflineComponentProvider
LOG [2022-03-02T20:05:00.816Z] @firebase/firestore: Firestore (9.6.7): FirestoreClient Initializing OnlineComponentProvider
LOG [2022-03-02T20:05:00.819Z] @firebase/firestore: Firestore (9.6.7): MemoryPersistence Starting transaction: Allocate target
LOG [2022-03-02T20:05:00.822Z] @firebase/firestore: Firestore (9.6.7): MemoryPersistence Starting transaction: Execute query
LOG [2022-03-02T20:05:00.823Z] @firebase/firestore: Firestore (9.6.7): QueryEngine Using full collection scan to execute query: Query(target=Target(CollectionName/DocumentID, orderBy: [__name__ (asc)]); limitType=F)
LOG [2022-03-02T20:05:00.827Z] @firebase/firestore: Firestore (9.6.7): Connection Creating WebChannel: https://firestore.googleapis.com/google.firestore.v1.Firestore/Listen/channel {"httpSessionIdParam":"gsessionid","initMessageHeaders":{"X-Goog-Api-Client":"gl-js/ fire/9.6.7","Content-Type":"text/plain","X-Firebase-GMPID":"***"},"messageUrlParams":{"database":"projects/***/databases/(default)"},"sendRawJson":true,"supportsCrossDomainXhr":true,"internalChannelParams":{"forwardChannelRequestTimeoutMs":600000},"forceLongPolling":false,"detectBufferingProxy":false}
LOG [2022-03-02T20:05:00.829Z] @firebase/firestore: Firestore (9.6.7): FirebaseAppCheckTokenProvider AppCheck not yet detected
LOG [2022-03-02T20:05:00.830Z] @firebase/firestore: Firestore (9.6.7): Connection Opening WebChannel transport.
LOG [2022-03-02T20:05:00.832Z] @firebase/firestore: Firestore (9.6.7): Connection WebChannel sending: {"database":"projects/***/databases/(default)","addTarget":{"documents":{"documents":["projects/***/databases/(default)/documents/CollectionName/DocumentID"]},"targetId":2}}
LOG [2022-03-02T20:05:01.404Z] @firebase/firestore: Firestore (9.6.7): Connection WebChannel transport opened.
LOG [2022-03-02T20:05:01.500Z] @firebase/firestore: Firestore (9.6.7): Connection WebChannel received: {"targetChange":{"targetChangeType":"ADD","targetIds":[2]}}
LOG [2022-03-02T20:05:01.500Z] @firebase/firestore: Firestore (9.6.7): Connection WebChannel received: {"documentDelete":{"document":"projects/***/databases/(default)/documents/CollectionName/DocumentID","readTime":"2022-03-02T20:05:01.382876Z","removedTargetIds":[2]}}
LOG [2022-03-02T20:05:01.500Z] @firebase/firestore: Firestore (9.6.7): Connection WebChannel received: {"targetChange":{"targetChangeType":"CURRENT","targetIds":[2],"resumeToken":"CgkI3NnN35yo9gI=","readTime":"2022-03-02T20:05:01.382876Z"}}
LOG [2022-03-02T20:05:01.500Z] @firebase/firestore: Firestore (9.6.7): Connection WebChannel received: {"targetChange":{"resumeToken":"CgkI3NnN35yo9gI=","readTime":"2022-03-02T20:05:01.382876Z"}}
LOG [2022-03-02T20:05:01.504Z] @firebase/firestore: Firestore (9.6.7): MemoryPersistence Starting transaction: Get last remote snapshot version
LOG [2022-03-02T20:05:01.506Z] @firebase/firestore: Firestore (9.6.7): MemoryPersistence Starting transaction: Apply remote event
LOG [2022-03-02T20:05:01.510Z] @firebase/firestore: Firestore (9.6.7): MemoryPersistence Starting transaction: notifyLocalViewChanges
LOG [2022-03-02T20:05:01.511Z] @firebase/firestore: Firestore (9.6.7): MemoryPersistence Starting transaction: Release target
LOG undefined
LOG [2022-03-02T20:05:01.515Z] @firebase/firestore: Firestore (9.6.7): Connection WebChannel sending: {"database":"projects/***/databases/(default)","removeTarget":2}
LOG [2022-03-02T20:05:01.564Z] @firebase/firestore: Firestore (9.6.7): Connection WebChannel received: {"targetChange":{"targetChangeType":"REMOVE","targetIds":[2]}}
I got the same issue but only on android. iOS is working just fine.
this is the log i got by Importing SetLogLevel from 'firebase/firestore' when i imported it from 'firebase/app' i didn't get anything :
LOG Running "testXconnection" with {"rootTag":11}
LOG [2022-03-04T16:43:17.505Z] @firebase/firestore: Firestore (9.6.7): FirebaseAuthCredentialsProvider Auth not yet detected
LOG [2022-03-04T16:43:17.516Z] @firebase/firestore: Firestore (9.6.7): FirestoreClient Using default OnlineComponentProvider
LOG [2022-03-04T16:43:17.519Z] @firebase/firestore: Firestore (9.6.7): FirestoreClient Using default OfflineComponentProvider
LOG [2022-03-04T16:43:17.519Z] @firebase/firestore: Firestore (9.6.7): FirestoreClient Initializing OfflineComponentProvider
LOG [2022-03-04T16:43:17.522Z] @firebase/firestore: Firestore (9.6.7): FirestoreClient Initializing OnlineComponentProvider
LOG [2022-03-04T16:43:17.527Z] @firebase/firestore: Firestore (9.6.7): MemoryPersistence Starting transaction: Allocate target
LOG [2022-03-04T16:43:17.532Z] @firebase/firestore: Firestore (9.6.7): MemoryPersistence Starting transaction: Execute query
LOG [2022-03-04T16:43:17.534Z] @firebase/firestore: Firestore (9.6.7): QueryEngine Using full collection scan to execute query: Query(target=Target(CollectionName/DocumentID, orderBy: [__name__ (asc)]); limitType=F)
LOG [2022-03-04T16:43:17.540Z] @firebase/firestore: Firestore (9.6.7): Connection Creating WebChannel: https://firestore.googleapis.com/google.firestore.v1.Firestore/Listen/channel {"httpSessionIdParam":"gsessionid","initMessageHeaders":{"X-Goog-Api-Client":"gl-js/ fire/9.6.7","Content-Type":"text/plain","X-Firebase-GMPID":"1:1055076983185:web:2338e7c6417ea4c5d77a30"},"messageUrlParams":{"database":"projects/textxconnection/databases/(default)"},"sendRawJson":true,"supportsCrossDomainXhr":true,"internalChannelParams":{"forwardChannelRequestTimeoutMs":600000},"forceLongPolling":false,"detectBufferingProxy":false}
LOG [2022-03-04T16:43:17.544Z] @firebase/firestore: Firestore (9.6.7): FirebaseAppCheckTokenProvider AppCheck not yet detected
LOG [2022-03-04T16:43:17.547Z] @firebase/firestore: Firestore (9.6.7): Connection Opening WebChannel transport.
LOG [2022-03-04T16:43:17.549Z] @firebase/firestore: Firestore (9.6.7): Connection WebChannel sending: {"database":"projects/textxconnection/databases/(default)","addTarget":{"documents":{"documents":["projects/textxconnection/databases/(default)/documents/CollectionName/DocumentID"]},"targetId":2}}
LOG [2022-03-04T16:43:17.837Z] @firebase/firestore: Firestore (9.6.7): Connection WebChannel transport opened.
ERROR [2022-03-04T16:43:27.547Z] @firebase/firestore: Firestore (9.6.7): Could not reach Cloud Firestore backend. Backend didn't respond within 10 seconds.
This typically indicates that your device does not have a healthy Internet connection at the moment. The client will operate in offline mode until it is able to successfully connect to the backend.
LOG [2022-03-04T16:43:27.588Z] @firebase/firestore: Firestore (9.6.7): MemoryPersistence Starting transaction: Release target
LOG [2022-03-04T16:43:27.598Z] @firebase/firestore: Firestore (9.6.7): Connection WebChannel sending: {"database":"projects/textxconnection/databases/(default)","removeTarget":2}
WARN Possible Unhandled Promise Rejection (id: 0):
FirebaseError: Failed to get document because the client is offline.
construct@[native code]
Wrapper@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false&app=com.testxconnection&modulesOnly=false&runModule=true:22813:64
construct@[native code]
_createSuperInternal@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false&app=com.testxconnection&modulesOnly=false&runModule=true:110646:322
FirebaseError@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false&app=com.testxconnection&modulesOnly=false&runModule=true:111260:27
construct@[native code]
_createSuperInternal@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false&app=com.testxconnection&modulesOnly=false&runModule=true:113611:322
Q@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false&app=com.testxconnection&modulesOnly=false&runModule=true:113850:26
next@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false&app=com.testxconnection&modulesOnly=false&runModule=true:131303:55
http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false&app=com.testxconnection&modulesOnly=false&runModule=true:130246:30
http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false&app=com.testxconnection&modulesOnly=false&runModule=true:29541:26
_callTimer@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false&app=com.testxconnection&modulesOnly=false&runModule=true:29461:17
callTimers@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false&app=com.testxconnection&modulesOnly=false&runModule=true:29662:19
__callFunction@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false&app=com.testxconnection&modulesOnly=false&runModule=true:3056:36
http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false&app=com.testxconnection&modulesOnly=false&runModule=true:2780:31
__guard@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false&app=com.testxconnection&modulesOnly=false&runModule=true:3007:15
callFunctionReturnFlushedQueue@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false&app=com.testxconnection&modulesOnly=false&runModule=true:2779:21
callFunctionReturnFlushedQueue@[native code]
i didn't hide anything because this is a test project just for this issue so here is the logs
And i would like to test on IOS, i have an Iphone but not a macbook so i can't currently test running on IOS
The log looks (I am a bit surprised there is no initiating of a backoff attempt though). I am unfortunately not able to reproduce this on iOS at the moment, but should be in a couple of days. In the meantime, if you have some spare cycles it would be interesting to see if you can use "firebase/firestore/lite" which uses plain HTTP for its networking. It does not support offline usage and onSnapshot listeners though.
I've started seeing this error on an app deployed in production that hasn't seen any changes in a while. Firebase SDK version: 9.6.5 and 9.6.8 as well. Multiple browsers.
Could it be something with AppCheck? The only change I see in the console is that starting today AppCheck is reporting client requests for Firestore in our project. Enforcing is not enabled though.
Also have seen this since this morning ~11AM ET. We are on 9.6.1 + React for web.
It also intermittently happens, some devs are able to reproduce while others aren't.
I've started seeing this error on an app deployed in production that hasn't seen any changes in a while. Firebase SDK version: 9.6.5 and 9.6.8 as well. Multiple browsers.
Could it be something with AppCheck? The only change I see in the console is that starting today AppCheck is reporting client requests for Firestore in our project. Enforcing is not enabled though.
In our case a third-party script (FullStory session recording) was interfering with Firestore requests. I don't know how it is intercepting XHR requests and what changed today in their script, but once we disabled it the Firestore issue went away. Sorry folks for polluting this issue, but maybe this will offer some clues on what might be the cause here.
it would be interesting to see if you can use "firebase/firestore/lite"
LOG Running "testXconnection" with {"rootTag":1}
LOG [2022-03-05T16:32:08.141Z] @firebase/firestore: Firestore (9.6.7_lite): ComponentProvider Initializing Datastore
LOG [2022-03-05T16:32:08.198Z] @firebase/firestore: Firestore (9.6.7_lite): RestConnection Sending: https://firestore.googleapis.com/v1/projects/textxconnection/databases/(default)/documents:batchGet {"documents":["projects/textxconnection/databases/(default)/documents/CollectionName/DocumentID"]}
LOG [2022-03-05T16:32:08.443Z] @firebase/firestore: Firestore (9.6.7_lite): RestConnection Received: [{"found":{"name":"projects/textxconnection/databases/(default)/documents/CollectionName/DocumentID","fields":{"test":{"stringValue":"test String value"}},"createTime":"2022-03-04T16:40:40.128561Z","updateTime":"2022-03-04T16:40:40.128561Z"},"readTime":"2022-03-05T16:32:07.583541Z"}]
LOG {"test": "test String value"}
Last line is the value stored in Firestore so it's worked maybe the issue come from a Firewall or i don't know i have no antivirus and disabled windows Defender so it's maybe coming from Android studio / Metro ? i try to see because I'll need to use onSnapshot listeners
Edit : Or maybe i can force request of the 'firebase/firestore" to be HTTP i currently don't find a way, every google searches redirect me to Firebase functions i continue searching.
Also seeing this with React Native on Android 12.
@sampajano
Seeing this intermittently on Linux too, in Electron.
Edit: @schmidt-sebastian did you mean to assign this to @sampajano or yourself?
Hi :) Could you try to enable the experimentalAutoDetectLongPolling flag and see if it solves the issue for you? Thanks! 😃
Code:
firebase.firestore().settings({ experimentalAutoDetectLongPolling: true });
Hi, it worked perfectly,
for maybe future readers i imported like this :
import { initializeFirestore } from 'firebase/firestore'
and used it like this :
const db = initializeFirestore(app, {
experimentalAutoDetectLongPolling: true
})
because i'm in v9
Thank you so much it is even faster than before ! :)
Fantastic! Glad it worked and thanks for sharing the results! 😃
What about Realtime Database?
and @sampajano what about cases where this error is caused by pausing the code for a few seconds in the debugger? (Edit: Actually it occurs in the debugger almost 100% of the time, even if there's no pausing, but only if a user is signed in, but probably because that's the only time we register listeners.)
It says it's offline even milliseconds before our listeners fire off actions in response to, apparently, being online. Maybe I'm just being fooled by offline persistence though?
@x-Wawa would you please re-open this issue?