firebase / firebase-tools

The Firebase Command Line Tools
MIT License
4.02k stars 937 forks source link

Failed to add many documents in to firestore emulator. #3183

Closed kenmasumitsu closed 1 year ago

kenmasumitsu commented 3 years ago

[REQUIRED] Environment info

firebase-tools:

9.5.0

Platform:

macOS

[REQUIRED] Test case

import admin = require("firebase-admin");
admin.initializeApp({ projectId: "project_id" });
const db = admin.firestore();

async function main() {
  const sleep = (msec: number) =>
    new Promise((resolve) => setTimeout(resolve, msec));

  for (let i = 0; i < 11000; i++) {
    const data = {
      foo: "foo",
      bar: "bar",
    };

    console.log("add", i);
    await db.collection("test").add(data);
    await sleep(10);
  }
}
main();

[REQUIRED] Steps to reproduce

  1. Run firebase emulator. firebase emulators:start
  2. Run the script above. npx ts-node src/index.ts

[REQUIRED] Expected behavior

All 11000 documents are added on the firestore.

[REQUIRED] Actual behavior

The script does not show any error now exceptions. However, not all documents exist the firestore. And about 1000 addition, many warning messages appear in firestore-debug.log.

Mar 03, 2021 10:41:27 AM com.google.net.webchannel.server.v8.BackChannel add
WARNING: Failed to send a new message due to too many pending messagings in the back channel (10001). May need enable flow control.
Mar 03, 2021 10:41:27 AM com.google.net.webchannel.server.v8.ChannelInternalImpl handle
WARNING: Server fails to send the message, abort the channel!

firestore-debug.log.zip

google-oss-bot commented 3 years ago

This issue does not have all the information required by the template. Looks like you forgot to fill out some sections. Please update the issue with more information.

kenmasumitsu commented 3 years ago

updated.

samtstern commented 3 years ago

@kenmasumitsu thank you for reporting this! Seems like a bug to me. As a workaround have you tried batching the documents? That could help.

yuchenshi commented 3 years ago

I've filed b/181873686 to internally track this.

TylerR909 commented 3 years ago

I'm unable to add anything via the Emulator UI.

Version Info ```zsh ➜ test java -version openjdk version "15.0.2" 2021-01-19 OpenJDK Runtime Environment AdoptOpenJDK (build 15.0.2+7) OpenJDK 64-Bit Server VM AdoptOpenJDK (build 15.0.2+7, mixed mode, sharing) ➜ test node -v v12.20.2 ➜ test npm -v 6.14.11 ➜ test firebase --version 9.5.0 ➜ test sw_vers ProductName: Mac OS X ProductVersion: 10.15.7 BuildVersion: 19H512 ```

My steps:

  1. Install firebase-tools via npm, login, select project
  2. mkdir test to create new sandbox directory
  3. firebase init selecting firestore, emulators, then setting up the emulators to use authentication and firestore emulators (everything else default, except selecting Yes to "download emulators now").
  4. firebase emulators:start
  5. Open UI in localhost:4000
  6. Navigate to Firestore Emulator, try to create my first collection and adding my first document, click save
  7. nothing happens
firestore-debug.log ```txt API endpoint: http://localhost:8080 If you are using a library that supports the FIRESTORE_EMULATOR_HOST environment variable, run: export FIRESTORE_EMULATOR_HOST=localhost:8080 Dev App Server is now running. Mar 07, 2021 11:04:38 AM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead INFO: Detected non-HTTP/2 connection. Mar 07, 2021 11:04:39 AM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead INFO: Detected HTTP/2 connection. Mar 07, 2021 11:04:47 AM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead INFO: Detected non-HTTP/2 connection. Mar 07, 2021 11:04:48 AM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead INFO: Detected non-HTTP/2 connection. *** shutting down gRPC server since JVM is shutting down *** server shut down ```
ui-debug.log ```txt Web / API server started at http://localhost:4000 ```
yuchenshi commented 3 years ago

@TylerR909 This issue tracks an issue regarding the Firestore Emulator on adding a lot of documents. It seems you're experiencing a different issue in Emulator UI. Would you mind opening a new issue at https://github.com/firebase/firebase-tools-ui/issues with your logs and findings? Also note that with the Emulator UI, there may be useful debug logs in your browser DevTools on the Emulator UI page, so please make sure to attach those when you file the new issue.

MidnightLightning commented 1 year ago

This appears to be the same issue as #4578

joehan commented 1 year ago

Duplicates #4578, let's use that one for tracking this issue.