Firebase Cloud Firestore throws "client is offline"

Viewed 35903

About 3 out of 4 times loading the page I get this error from the firestore client SDK (web). This slows development down tremendously. Auth, Realtime DB and Storage work perfectly fine.

Failed to get document because the client is offline.

Error

Is there something I can do about this?

16 Answers

There's currently an interaction between the clients and routing on the backend that results in this problem. As a result the client believes the network is failing and goes offline.

We'll be rolling out a fix for this soon. Exact times I can't promise but this is among our top priority issues to fix.

Thanks for your patience.

For me, the same error happened when

  1. project_id is wrong
  2. port for emulator is 8081 instead of 8080. (when port was 8081 the emulator was working well, with UI opened normally and so on but the error kept showing. I fixed the problem by changing the port back to 8080)

The error message is very misleading.

I have just spent about 3 hours trying to fix it. There was something wrong with my emulator. I had to remove it, then created new and now it is working. So if you face this issue, give it try.

The problem might occur because you're integrating firebase 'web' SDK in your React Native (RN CLI not Expo) app. So in order to use firebase in your react native app you must follow this tutorial: https://rnfirebase.io/

It must work.

For me, just restarting the emulator fixed it.

In my app as well this error occurs at the first run after installation. I was able to get rid of above bug by refreshing/restarting the Activity.

if (e.getMessage().equals("Failed to get document because the client is offline.")){
     finish();
     startActivity(getIntent());
}

This code must be placed in addOnFailureListener.

In my case, I was using a leading slash in the database URL:

admin.initializeApp({
    credential: admin.credential.cert(CREDENTIALS_PATH), 
    databaseURL: "https://databasename.firebaseio.com/"
                                      // remove this ^
});

I had some problem. but I've just fixed it. check your projectId is correct. when you use cloud firestore, you need it.

export const environment = {
  production: false,
  firebaseConfig: {
    apiKey: 'XYZ',
    authDomain: 'XYZ.firebaseapp.com',
    databaseURL: 'https://XYZ.firebaseio.com',
    storageBucket: 'XYZ.appspot.com',
    projectId: 'XYZ' // <--- make sure project ID is here 
  }
};

For me, enabling ({ synchronizeTabs: true } ) seems to have helped.

Just in case if someone ever faces this issue on the web (server side code), simply try restarting the server and again ping the endpoint that connects to firebase. This worked for me!

In my case I was using Chrome Extension Moesif CORS. I disabled the extension and it worked.

In my case, I was getting this issue along with a warning that I should change my database location as it was in a different region.
I added a databaseURL property in the firebaseconfig with the url of my dsatabase and it worked properly after that.

My problem was that I previously tested my app with the firebase-local-emulator and therefore had some configurations for it still enabled, for example:

Firebase.firestore.apply {
    if (DomainConstants.isOnTest) useEmulator("10.0.2.2", 8080)
}

Because I forgot to set isOnTest = false, the app relied on the firebase-local-emulators data (which was not running) and threw client is offline error.

Long story short: Check if you configured your project using firebase-local-emulator and turn it off when you want to use your "real" database

Saw this error in the console, Enabling Datastore might help.

@firebase/firestore: Firestore (9.6.9): Could not reach Cloud Firestore backend. Connection failed 1 times. Most recent error: FirebaseError: [code=not-found]: The project my-project does not exist or it does not contain an active Cloud Datastore or Cloud Firestore database. Please visit http://console.cloud.google.com to create a project or https://console.cloud.google.com/datastore/setup?project=my-project to add a Cloud Datastore or Cloud Firestore database. Note that Cloud Datastore or Cloud Firestore always have an associated App Engine app and this app must not be disabled. 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.

Try to use VPN, It will work!. Me i switched to VPN and it worked 100%. Sometimes Firebase fail to respond to IPs addresses of some countries.

Related