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

Write back from local web application to the local emulator firestore database is not working #2237

Closed
adiazarya100 opened this issue May 13, 2020 · 6 comments

Comments

@adiazarya100
Copy link

[REQUIRED] Environment info

firebase-tools: 8.2.0

Platform: macOS

[REQUIRED] Test case

Having a project with imported data from my production bucket.
I start the emulator with:
firebase emulators:start --only functions,firestore --inspect-functions --import=MY_DIR
I can see the data in my web application.
When I try to write back to the emulator the request is pending forever

More info here: stackoverflow

[REQUIRED] Steps to reproduce

  • Import data from your bucket to your local machine
  • Create a firebase-export-metadata.json file that points to your exported data using this trick link
  • initialize your web application with this configuration documation
  • Lunch the emulator with this command firebase emulators:start --only functions,firestore --inspect-functions --import=MY_DIR
  • Try to write back to the emulator. use update, create, etc. methods

[REQUIRED] Expected behavior

Write back successfully to the emulator.

[REQUIRED] Actual behavior

The request is pending forever. after few minutes you will get a time out. Data does not change

This is my web application config file (Client-side):

import firebase from 'firebase/app';
import 'firebase/firestore';

const { NODE_ENV } = process.env;
const isDevelop = NODE_ENV === 'develop';

const productionOptions = {
  ...
  ...
}

const developOptions = {
  ...
  ...
}

firebase.initializeApp(isDevelop ? developOptions : productionOptions);

const db = firebase.firestore();
const auth = firebase.auth();
const { currentUser } = auth;

if (isDevelop) {
  db.settings({
    host: 'localhost:8080',
    ssl: false
  });
  firebase.functions().useFunctionsEmulator('http://localhost:5001');
}

export {
  firebase,
  db,
  auth,
  currentUser
};

Update method:

  • field => The collection I meant to update for example: users
  • id => The id of this specific document
  • params => The new parameters to update for example: { name: 'alice' }
async function update({ field, id, params }) { 
   try {
    const collection = db.collection(field);
    await collection.doc(id).update(params) // pending forever!
   } catch(e){
     console.log(e)
   }
}

Emulator output:

i  emulators: Starting emulators: functions, firestore
✔  hub: emulator hub started at http://localhost:4400
⚠  functions: You are running the functions emulator in debug mode (port=9229). This means that functions will execute in sequence rather than in parallel.
⚠  Your requested "node" version "8" doesn't match your global version "10"
✔  functions: functions emulator started at http://localhost:5001
i  firestore: Importing data from /Users/adi/Desktop/myproject-admin/cloudFunctions/functions/2020-05-07T09:36:11_57193/2020-05-07T09:36:11_57193.overall_export_metadata
⚠  firestore: The emulator will default to allowing all reads and writes. Learn more about this option: https://firebase.google.com/docs/emulator-suite/install_and_configure#security_rules_configuration.
i  firestore: firestore emulator logging to firestore-debug.log
✔  firestore: firestore emulator started at http://localhost:8080
i  firestore: For testing set FIRESTORE_EMULATOR_HOST=localhost:8080
i  functions: Watching "/Users/adi/Desktop/myproject-admin/cloudFunctions/functions" for Cloud Functions...
>  Debugger listening on ws://localhost:9229/af9a2bd6-e5b0-4fa0-8103-53fab69a2a45
⚠  functions: Your GOOGLE_APPLICATION_CREDENTIALS environment variable points to ./src/utils/serviceAccountKeyDevelop.json. Non-emulated services will access production using these credentials. Be careful!
>  (node:12364) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
✔  functions[api]: http function initialized (http://localhost:5001/myproject-dev/us-central1/api).
✔  functions[indexUsers]: firestore function initialized.
✔  functions[indexSubCategories]: firestore function initialized.
✔  functions[indexEvents]: firestore function initialized.
✔  functions[userAddedToGroup]: firestore function initialized.
i  functions[calculateLeaderBoard]: function ignored because the pubsub emulator does not exist or is not running.
i  functions[missionsUpdate]: function ignored because the pubsub emulator does not exist or is not running.
✔  emulators: All emulators started, it is now safe to connect.
@samtstern
Copy link
Contributor

@adiazarya100 thanks for filing this issue (I saw your StackOverflow post as well). Can you show the content of the firestore-debug.log file?

@adiazarya100
Copy link
Author

adiazarya100 commented May 14, 2020

Hi @samtstern
Sorry, I forgot to add my debug log.
here it is:

May 14, 2020 3:38:35 PM com.google.cloud.datastore.emulator.firestore.webchannel.JsonToProtoConverter toWriteRequest
WARNING: invalid message: {"streamToken":"MA==","writes":[{"update":{"name":"projects/myproject-dev/databases/(default)/documents/rooms/7KcQem0vykF1jL3ao63X","fields":{"imageUrl":{"stringValue":"http://res.cloudinary.com/myproject-dev/image/upload/v1588605567/Sport/NFL/square_n34sr5.jpg"},"subCategoryId":{"stringValue":"2f80YwVU4tyZqck5n8kt"},"updatedAt":{"timestampValue":{"seconds":1589459915,"nanos":271000000}}}},"updateMask":{"fieldPaths":["imageUrl","subCategoryId","updatedAt"]},"currentDocument":{"exists":true}}]}
May 14, 2020 3:38:35 PM com.google.net.webchannel.server.common.ChannelProcessor run
WARNING: Failed to consume the event.
java.lang.RuntimeException: com.google.protobuf.InvalidProtocolBufferException: JsonObject
	at com.google.cloud.datastore.emulator.firestore.webchannel.JsonToProtoConverter.toWriteRequest(JsonToProtoConverter.java:33)
	at com.google.cloud.datastore.emulator.firestore.webchannel.FirestoreV1WebChannelAdapter$FirestoreWriteHandler.onMessage(FirestoreV1WebChannelAdapter.java:141)
	at com.google.cloud.datastore.emulator.firestore.webchannel.FirestoreV1WebChannelAdapter$FirestoreWriteHandler.onMessage(FirestoreV1WebChannelAdapter.java:111)
	at com.google.net.webchannel.server.v8.ChannelInternalImpl.onMessage(ChannelInternalImpl.java:484)
	at com.google.net.webchannel.server.v8.ForwardChannel.deliverMessage(ForwardChannel.java:114)
	at com.google.net.webchannel.server.v8.ForwardChannel.processPendingRequest(ForwardChannel.java:93)
	at com.google.net.webchannel.server.v8.ForwardChannel.consume(ForwardChannel.java:67)
	at com.google.net.webchannel.server.v8.ForwardChannel.add(ForwardChannel.java:60)
	at com.google.net.webchannel.server.v8.ChannelInternalImpl.handleRequestParams(ChannelInternalImpl.java:260)
	at com.google.net.webchannel.server.v8.ChannelInternalImpl.processSessionRequest(ChannelInternalImpl.java:317)
	at com.google.net.webchannel.server.v8.ChannelInternalImpl.handle(ChannelInternalImpl.java:142)
	at com.google.net.webchannel.server.v8.ChannelInternalImpl.consume(ChannelInternalImpl.java:78)
	at com.google.net.webchannel.server.common.ChannelProcessor.run(ChannelProcessor.java:80)
Caused by: com.google.protobuf.InvalidProtocolBufferException: JsonObject
	at com.google.cloud.datastore.emulator.firestore.webchannel.jsonformatfork.JsonFormat$ParserImpl.merge(JsonFormat.java:1349)
	at com.google.cloud.datastore.emulator.firestore.webchannel.jsonformatfork.JsonFormat$Parser.merge(JsonFormat.java:451)
	at com.google.cloud.datastore.emulator.firestore.webchannel.JsonToProtoConverter.toWriteRequest(JsonToProtoConverter.java:30)
	... 12 more

@samtstern
Copy link
Contributor

@adiazarya100 thanks for the extra logs! This looks like it's a bug in the Firestore emulator, it's saying the proto is invalid but that shouldn't be possible for a request coming from the SDK.

@yuchenshi hopefully can look into it or re-assign.

@yuchenshi
Copy link
Member

Would you mind updating the version of your Firestore client SDK and try again? Let me know if the new SDK version if that still fails.

Also, I'm having trouble to reproduce this and I'd really appreciate it if you can simplify your repro to something like this:

await collection.doc(id).update({
  field1: ...,
  field2: ...,
}) 

Where fields are the actual field values that you used to trigger this bug. I see you must have some Timestamps (or Dates) in there, but I need the exact way how you created such a payload and the exact value.

@samtstern samtstern added the Needs: Author Feedback Issues awaiting author feedback label Jun 2, 2020
@google-oss-bot
Copy link
Contributor

Hey @adiazarya100. We need more information to resolve this issue but there hasn't been an update in 7 weekdays. I'm marking the issue as stale and if there are no new updates in the next 3 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!

@adiazarya100
Copy link
Author

adiazarya100 commented Jun 4, 2020

Hey,
I just updated the firebase client SDK to 7.14.6 as you suggested and it works perfectly!
Thank you so much!

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

4 participants