firebase / firebase-js-sdk

Firebase Javascript SDK
https://firebase.google.com/docs/web/setup
Other
4.86k stars 893 forks source link

@firebase/firestore: Firestore (9.23.0): Could not reach Cloud Firestore backend. Connection failed 1 times. Most recent error: FirebaseError: [code=unavailable]: The operation could not be completed 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. #8576

Open juan-carvajal opened 1 month ago

juan-carvajal commented 1 month ago

Operating System

Multiple operating systems, mostly iOS and Android

Environment (if applicable)

Multiple browsers, mostly mobile versions of Safari and Chrome

Firebase SDK Version

9.23.0

Firebase SDK Product(s)

Firestore

Project Tooling

Vue 3 SPA app, created with Quasar framework V2. Package using Vite.

Detailed Problem Description

Some of our users have encountered an issue where our application does not start from the corporate network. We found that the listener has a slow response time that is not within the timeout of 10 seconds, i.e. the request does not go through and the application does not receive data from firebase.

This is what my setup looks now:

import { initializeApp } from 'firebase/app';
import {
  connectFirestoreEmulator,
  initializeFirestore,
  setLogLevel,
  onSnapshotsInSync,
} from 'firebase/firestore';
import { getAuth, connectAuthEmulator } from 'firebase/auth';
import { getPerformance } from 'firebase/performance';
import { getAnalytics } from 'firebase/analytics';
import { getStorage, connectStorageEmulator } from 'firebase/storage';
import { getFunctions, connectFunctionsEmulator } from 'firebase/functions';
import { boot } from 'quasar/wrappers';
import { useAuthStore } from 'src/stores/auth-store';

const firebaseConfig = {
 ...
};

const firebaseApp = initializeApp(firebaseConfig);

setLogLevel('debug');
const db = initializeFirestore(firebaseApp, {
  experimentalForceLongPolling: true,
  experimentalLongPollingOptions: {
    timeoutSeconds: 30,
  },
});
const performance = getPerformance(firebaseApp);
const auth = getAuth(firebaseApp);
const analytics = getAnalytics(firebaseApp);
const storage = getStorage(firebaseApp);
const functions = getFunctions(firebaseApp);

// Algunas veces falla el emulator de autenticación
// Cuando se encuentra dentro de la función boot

if (process.env.DEV && process.env.USE_AUTH_EMULATOR == 'true') {
  connectAuthEmulator(auth, 'http://127.0.0.1:9099', { disableWarnings: true });
}

export default boot(() => {
  const { handleUserChange } = useAuthStore();
  if (process.env.DEV) {
    connectFirestoreEmulator(db, 'localhost', 8081);
    connectStorageEmulator(storage, 'localhost', 9199);
    connectFunctionsEmulator(functions, 'localhost', 5001);
  }
  auth.onAuthStateChanged(handleUserChange);

  onSnapshotsInSync(db, {
    next: (metadata) => {
      console.log('Snapshots in sync', metadata);
    },
    error: (error) => {
      console.error('Error in snapshots in sync', error);
    },
    complete: () => {
      console.log('Snapshots in sync complete');
    },
  });
});

export { auth, db, performance, analytics, storage, functions };

Setting experimentalAutoDetectLongPolling or experimentalForceLongPolling does not help.

Results from https://debug-my.firebaseapp.com/ found in test.txt Browser trace after setLogLevel('debug') found in log.txt

Steps and code to reproduce issue

No idea, this appears to happen intermittently and is more prevalent with certain ISP/mobile internet providers (TIGO). This is not an isolated case; most errors come from mobile devices. There should be sufficient internet speed in most cases, but the error still shows up. 99% of our users are from Colombia.

google-oss-bot commented 1 month ago

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

wu-hui commented 1 month ago

From you logs, it seems like the connection was recovered later? Is this what you observed as well?

You can also try to upgrade to the latest, we have done some changes to our network transportation layer recently that might be helpful.

google-oss-bot commented 1 day ago

Hey @juan-carvajal. We need more information to resolve this issue but there hasn't been an update in 5 weekdays. I'm marking the issue as stale and if there are no new updates in the next 5 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!