Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Occasional onSnapshot 30-second-delay when opening the application #8679

Open
DevSchmidtchen opened this issue Dec 13, 2024 · 1 comment
Open

Comments

@DevSchmidtchen
Copy link

Operating System

iOS 18.1.1

Environment (if applicable)

Ionic / Capacitor

Firebase SDK Version

10.14.1

Firebase SDK Product(s)

Firestore

Project Tooling

Nuxt Ionic mobile app with Capacitor

Detailed Problem Description

Our users regularly report the issue that they are not being automatically logged into our mobile app even if they were before. It commonly takes exactly 30 seconds until the auto-login actually happens.
This doesn't happen on every login, but it's annoying once it does happen.

I added logging to the whole process and noticed that the delay comes from the onSnapshot call on our user document. Here's how the code at this point currently looks like:

const db = getFirestore();

const userRef = doc(db, "users", user.uid);

this.unsubscribeUser?.();

const initiationTime = Date.now();

this.unsubscribeUser = onSnapshot(userRef, async (userSnap) => {
    if (!userSnap.exists()) {
      newUser = true;
    }

    const snapshotInitiationDuration = Date.now() - initiationTime;

    // ...

Once the bug happens, the snapshotInitiationDuration is most often pretty much exactly at 30 seconds.

Here are the (relevant) debug logs (taken from Sentry, some details redacted):

[2024-12-13T09:46:49.145Z]  @firebase/firestore: Firestore (10.14.1): FirebaseAuthCredentialsProvider Auth detected
[2024-12-13T09:46:49.173Z]  @firebase/firestore: Firestore (10.14.1): FirestoreClient Received user= ...
[2024-12-13T09:46:49.178Z]  @firebase/firestore: Firestore (10.14.1): FirestoreClient Using default OnlineComponentProvider
[2024-12-13T09:46:49.178Z]  @firebase/firestore: Firestore (10.14.1): FirestoreClient Using default OfflineComponentProvider
[2024-12-13T09:46:49.178Z]  @firebase/firestore: Firestore (10.14.1): FirestoreClient Initializing OfflineComponentProvider
[2024-12-13T09:46:49.180Z]  @firebase/firestore: Firestore (10.14.1): FirestoreClient Initializing OnlineComponentProvider
[2024-12-13T09:46:49.181Z]  @firebase/firestore: Firestore (10.14.1): MemoryPersistence Starting transaction: Allocate target
[2024-12-13T09:46:49.183Z]  @firebase/firestore: Firestore (10.14.1): MemoryPersistence Starting transaction: Execute query
[2024-12-13T09:46:49.183Z]  @firebase/firestore: Firestore (10.14.1): QueryEngine Using full collection scan to execute query: Query(target=Target(users/..., orderBy: [__name__ (asc)]); limitType=F)
[2024-12-13T09:46:49.185Z]  @firebase/firestore: Firestore (10.14.1): WebChannelConnection Creating RPC 'Listen' stream 0x12b86423: https://firestore.googleapis.com/google.firestore.v1.Firestore/Listen/channel {"httpSessionIdParam":"gsessionid","initMessageHeaders":{"X-Goog-Api-Client":"gl-js/ fire/10.14.1","Content-Type":"text/plain","X-Firebase-GMPID":"...","Authorization":"Bearer ..."},"messageUrlParams":{"database":"projects/.../databases/(default)"},"sendRawJson":true,"supportsCrossDomainXhr":true,"internalChannelParams":{"forwardChannelRequestTimeoutMs":600000},"forceLongPolling":false,"detectBufferingProxy":true,"useFetchStreams":true,"encodeInitMessageHeaders":true}
[2024-12-13T09:46:49.186Z]  @firebase/firestore: Firestore (10.14.1): FirebaseAppCheckTokenProvider AppCheck not yet detected
[2024-12-13T09:46:49.189Z]  @firebase/firestore: Firestore (10.14.1): WebChannelConnection Opening RPC 'Listen' stream 0x12b86423 transport.
[2024-12-13T09:46:49.190Z]  @firebase/firestore: Firestore (10.14.1): WebChannelConnection RPC 'Listen' stream 0x12b86423 sending: {"database":"projects/.../databases/(default)","addTarget":{"documents":{"documents":["projects/.../databases/(default)/documents/users/..."]},"targetId":2}}
POST: https://firestore.googleapis.com/google.firestore.v1.Firestore/Listen/channel?VER=8&database=projects%2F...%2Fdatabases%2F(default)&RID=...&CVER=22&X-HTTP-Session-Id=gsessionid&zx=sst6ct6mapfl&t=1 [200]
[2024-12-13T09:46:49.377Z]  @firebase/firestore: Firestore (10.14.1): WebChannelConnection RPC 'Listen' stream 0x12b86423 transport opened.
GET: https://firestore.googleapis.com/google.firestore.v1.Firestore/Listen/channel?gsessionid=...&VER=8&database=projects%2F...%2Fdatabases%2F(default)&RID=rpc&SID=...&AID=0&CI=0&TYPE=xmlhttp&zx=ahr0p9ed85lg&t=1 [200]
[2024-12-13T09:46:49.457Z]  @firebase/firestore: Firestore (10.14.1): WebChannelConnection RPC 'Listen' stream 0x12b86423 detected no buffering proxy
[2024-12-13T09:47:19.460Z]  @firebase/firestore: Firestore (10.14.1): WebChannelConnection RPC 'Listen' stream 0x12b86423 received: {"targetChange":{"targetChangeType":"ADD","targetIds":[2]}}
[2024-12-13T09:47:19.461Z]  @firebase/firestore: Firestore (10.14.1): WebChannelConnection RPC 'Listen' stream 0x12b86423 received: {"documentChange":{"document":{"name":"projects/.../databases/(default)/documents/users/...","fields":..

As you can see, there is this big time gap between running onSnapshot and actually retrieving the document.

Steps and code to reproduce issue

Unfortunately, I wasn't able to consistently reproduce the issue, and therefore, I'm relying on logging other users' experiences.

@DevSchmidtchen DevSchmidtchen added new A new issue that hasn't be categoirzed as question, bug or feature request question labels Dec 13, 2024
@google-oss-bot
Copy link
Contributor

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

@jbalidiong jbalidiong added api: firestore needs-attention and removed needs-triage new A new issue that hasn't be categoirzed as question, bug or feature request labels Dec 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants