Skip to content

Batched writes failing in 8.6.2 #4953

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

Closed
halloweenman opened this issue May 28, 2021 · 5 comments · Fixed by #4971
Closed

Batched writes failing in 8.6.2 #4953

halloweenman opened this issue May 28, 2021 · 5 comments · Fixed by #4971
Assignees

Comments

@halloweenman
Copy link

halloweenman commented May 28, 2021

[REQUIRED] Describe your environment

Firebase hosting
Node v14.15.1

[REQUIRED] Describe the problem

A simple batch write, like that shown in your online example below will hang, no error message.

Our app was working fine in all versions prior to installing 8.6.2

Steps to reproduce:

Relevant Code:

// Get a new write batch
var batch = firebase.firestore().batch();

// Set the value of 'NYC'
var nycRef = firebase.firestore().collection("cities").doc("NYC");
batch.set(nycRef, {name: "New York City"});



// Commit the batch
batch.commit().then(() => {
    // ...
});
@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.

@looptheloop88
Copy link

Hi @stucker71, I wasn't able to replicate the issue. I tried all 8.6.+ versions and worked fine. The field was added to the document and the success callback in batch.commit() was called.

Would you mind sharing a minimal, but complete sample of a project that I can run locally to replicate the issue?

@halloweenman
Copy link
Author

halloweenman commented Jun 2, 2021

With our web app It appears that the issue occurs when the batched write follows on from the signInAnonymously() function.

Please try the following code, it will fail with 8.6.3. It will return "batch started" but not "batch done" :

firebase.auth().signOut()
      .then(() => {

        firebase.auth().signInAnonymously()
          .then(() => {

            console.info("batch started");

            // Get a new write batch
            var batch = firebase.firestore().batch();

            // Set the value of 'NYC'
            var nycRef = firebase.firestore().collection("cities").doc("NYC");
            batch.set(nycRef, { name: "New York City" });

            // Commit the batch
            batch.commit().then(() => {
              console.info("batch done");
            });
          });
      });

I'm using the following basic rules:

rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read, write: if true;
    }
  }
}

However, the following code will succeed:

firebase.auth().signOut()
      .then(() => {
            console.info("batch started");

            // Get a new write batch
            var batch = firebase.firestore().batch();

            // Set the value of 'NYC'
            var nycRef = firebase.firestore().collection("cities").doc("NYC");
            batch.set(nycRef, { name: "New York City" });

            // Commit the batch
            batch.commit().then(() => {
              console.info("batch done");
          });
      });

If I revert our project to 8.6.1 then the issue does not occur.

@looptheloop88
Copy link

Hi @stucker71, I was able to reproduce the issue now using the additional code snippets that you've shared. I also enabled firebase.firestore.setLogLevel('debug'); and got the following logs:

Write batch after firebase.auth().signInAnonymously()

batch started
logger.ts:115 [2021-06-02T18:18:53.296Z]  @firebase/firestore: Firestore (8.6.3): FirestoreClient Using default OnlineComponentProvider
logger.ts:115 [2021-06-02T18:18:53.296Z]  @firebase/firestore: Firestore (8.6.3): FirestoreClient Using default OfflineComponentProvider
logger.ts:115 [2021-06-02T18:18:53.296Z]  @firebase/firestore: Firestore (8.6.3): FirestoreClient Initializing OfflineComponentProvider
logger.ts:115 [2021-06-02T18:18:53.298Z]  @firebase/firestore: Firestore (8.6.3): FirestoreClient Initializing OnlineComponentProvider
logger.ts:115 [2021-06-02T18:18:53.299Z]  @firebase/firestore: Firestore (8.6.3): MemoryPersistence Starting transaction: Locally write mutations
logger.ts:115 [2021-06-02T18:18:53.301Z]  @firebase/firestore: Firestore (8.6.3): MemoryPersistence Starting transaction: Get next mutation batch
logger.ts:115 [2021-06-02T18:18:53.302Z]  @firebase/firestore: Firestore (8.6.3): MemoryPersistence Starting transaction: Get next mutation batch
logger.ts:115 [2021-06-02T18:18:53.302Z]  @firebase/firestore: Firestore (8.6.3): Connection Creating WebChannel: https://firestore.googleapis.com/google.firestore.v1.Firestore/Write/channel {"httpSessionIdParam":"gsessionid","initMessageHeaders":{"X-Goog-Api-Client":"gl-js/ fire/8.6.3","Content-Type":"text/plain","X-Firebase-GMPID":"<app id>"},"messageUrlParams":{"database":"projects/<project id>/databases/(default)"},"sendRawJson":true,"supportsCrossDomainXhr":true,"internalChannelParams":{"forwardChannelRequestTimeoutMs":600000},"forceLongPolling":false,"detectBufferingProxy":false,"httpHeadersOverwriteParam":"$httpHeaders"}
logger.ts:115 [2021-06-02T18:18:53.307Z]  @firebase/firestore: Firestore (8.6.3): FirebaseCredentialsProvider Auth detected
logger.ts:115 [2021-06-02T18:18:53.307Z]  @firebase/firestore: Firestore (8.6.3): FirestoreClient Received user= qMDLXhMKHzRv4KKZxPvBGFMik2e2
logger.ts:115 [2021-06-02T18:18:53.308Z]  @firebase/firestore: Firestore (8.6.3): RemoteStore RemoteStore received new credentials
logger.ts:115 [2021-06-02T18:18:53.308Z]  @firebase/firestore: Firestore (8.6.3): RemoteStore Stopping write stream with 1 pending writes
logger.ts:115 [2021-06-02T18:18:53.309Z]  @firebase/firestore: Firestore (8.6.3): SyncEngine User change. New user: uid:qMDLXhMKHzRv4KKZxPvBGFMik2e2
logger.ts:115 [2021-06-02T18:18:53.309Z]  @firebase/firestore: Firestore (8.6.3): MemoryPersistence Starting transaction: Handle user change
logger.ts:115 [2021-06-02T18:18:53.309Z]  @firebase/firestore: Firestore (8.6.3): MemoryPersistence Starting transaction: Get next mutation batch
logger.ts:115 [2021-06-02T18:18:53.310Z]  @firebase/firestore: Firestore (8.6.3): PersistentStream stream callback skipped by getCloseGuardedDispatcher.

After firebase.auth().signOut()

[2021-06-02T18:18:57.994Z]  @firebase/firestore: Firestore (8.6.3): AsyncQueue Visibility state changed to hidden
logger.ts:115 [2021-06-02T18:20:10.812Z]  @firebase/firestore: Firestore (8.6.3): AsyncQueue Visibility state changed to visible
logger.ts:115 [2021-06-02T18:20:13.769Z]  @firebase/firestore: Firestore (8.6.3): FirestoreClient Received user= null
logger.ts:115 [2021-06-02T18:20:13.769Z]  @firebase/firestore: Firestore (8.6.3): RemoteStore RemoteStore received new credentials
logger.ts:115 [2021-06-02T18:20:13.770Z]  @firebase/firestore: Firestore (8.6.3): SyncEngine User change. New user: anonymous-user
logger.ts:115 [2021-06-02T18:20:13.770Z]  @firebase/firestore: Firestore (8.6.3): MemoryPersistence Starting transaction: Handle user change
logger.ts:115 [2021-06-02T18:20:13.771Z]  @firebase/firestore: Firestore (8.6.3): MemoryPersistence Starting transaction: Get next mutation batch
logger.ts:115 [2021-06-02T18:20:13.772Z]  @firebase/firestore: Firestore (8.6.3): MemoryPersistence Starting transaction: Get next mutation batch
logger.ts:115 [2021-06-02T18:20:13.773Z]  @firebase/firestore: Firestore (8.6.3): Connection Creating WebChannel: https://firestore.googleapis.com/google.firestore.v1.Firestore/Write/channel {"httpSessionIdParam":"gsessionid","initMessageHeaders":{"X-Goog-Api-Client":"gl-js/ fire/8.6.3","Content-Type":"text/plain","X-Firebase-GMPID":"<app id>"},"messageUrlParams":{"database":"projects/<project id>/databases/(default)"},"sendRawJson":true,"supportsCrossDomainXhr":true,"internalChannelParams":{"forwardChannelRequestTimeoutMs":600000},"forceLongPolling":false,"detectBufferingProxy":false,"httpHeadersOverwriteParam":"$httpHeaders"}
logger.ts:115 [2021-06-02T18:20:13.775Z]  @firebase/firestore: Firestore (8.6.3): Connection Opening WebChannel transport.
logger.ts:115 [2021-06-02T18:20:13.776Z]  @firebase/firestore: Firestore (8.6.3): Connection WebChannel sending: {"database":"projects/<project id>/databases/(default)"}
logger.ts:115 [2021-06-02T18:20:13.988Z]  @firebase/firestore: Firestore (8.6.3): Connection WebChannel transport opened.
logger.ts:115 [2021-06-02T18:20:14.197Z]  @firebase/firestore: Firestore (8.6.3): Connection WebChannel received: {"streamId":"0","streamToken":"GRBoQgKB9LW1"}
logger.ts:115 [2021-06-02T18:20:14.198Z]  @firebase/firestore: Firestore (8.6.3): Connection WebChannel sending: {"streamToken":"GRBoQgKB9LW1","writes":[{"update":{"name":"projects/<project id>databases/(default)/documents/cities/NYC","fields":{"name":{"stringValue":"New York City"}}}}]}
logger.ts:115 [2021-06-02T18:20:14.478Z]  @firebase/firestore: Firestore (8.6.3): Connection WebChannel received: {"streamToken":"EAEZEGhCAoH0tbU=","writeResults":[{"updateTime":"2021-06-02T18:20:14.469092Z"}],"commitTime":"2021-06-02T18:20:14.469092Z"}
logger.ts:115 [2021-06-02T18:20:14.480Z]  @firebase/firestore: Firestore (8.6.3): MemoryPersistence Starting transaction: Acknowledge batch
anon.html:61 batch done
logger.ts:115 [2021-06-02T18:20:14.483Z]  @firebase/firestore: Firestore (8.6.3): MemoryPersistence Starting transaction: Get next mutation batch
logger.ts:115 [2021-06-02T18:20:24.020Z]  @firebase/firestore: Firestore (8.6.3): AsyncQueue Visibility state changed to hidden
logger.ts:115 [2021-06-02T18:20:36.031Z]  @firebase/firestore: Firestore (8.6.3): AsyncQueue Visibility state changed to visible

@schmidt-sebastian
Copy link
Contributor

Thank you for the repro. I will take a look at this.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants