firebase-js-sdk icon indicating copy to clipboard operation
firebase-js-sdk copied to clipboard

@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.

Open juan-carvajal opened this issue 1 year ago • 1 comments

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.

juan-carvajal avatar Oct 16 '24 18:10 juan-carvajal

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

google-oss-bot avatar Oct 16 '24 18:10 google-oss-bot

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.

wu-hui avatar Oct 21 '24 16:10 wu-hui

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!

google-oss-bot avatar Nov 21 '24 02:11 google-oss-bot

Since there haven't been any recent updates here, I am going to close this issue.

@juan-carvajal if you're still experiencing this problem and want to continue the discussion just leave a comment here and we are happy to re-open this.

google-oss-bot avatar Nov 28 '24 02:11 google-oss-bot