Skip to content

Firebase v9 setDoc() doesn't resolve or reject when using emulator #5436

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
theryan722 opened this issue Sep 3, 2021 · 18 comments
Closed

Firebase v9 setDoc() doesn't resolve or reject when using emulator #5436

theryan722 opened this issue Sep 3, 2021 · 18 comments
Assignees
Labels
testing-sdk testing with emulator v9

Comments

@theryan722
Copy link

theryan722 commented Sep 3, 2021

[REQUIRED] Describe your environment

  • Operating System version: Windows 10
  • Browser version: Google Chrome 92.0.4515.159
  • Firebase SDK version: v9.0.1 (modular) (Tested with both v9.0.1 and v9.0.0)
  • Firebase tools: v9.17.0
  • Firebase Product: Firestore

[REQUIRED] Describe the problem

Calling setDoc() when testing local using the emulator writes the document, but the function neither resolves or rejects. I've tried wrapping setDoc() in a try/catch block, no errors.

I can read documents fine and other tasks, but writing is what doesn't resolve.

Eventually, if I leave the page open long enough, I get this error:
image

and than this warning:
image

Steps to reproduce:

Use the new modular v9 api for firestore with the local emulator suite, and write to a document (existing or non-existing) using setDoc().

Relevant Code:

try {
    console.log('before');
    await setDoc(doc(firestore, '/test/test'), { hello: 'world!' });
    console.log('not running after');
} catch (e) {
    console.log('errored: ', e);
}
@jbalidiong jbalidiong added testing-sdk testing with emulator v9 labels Sep 3, 2021
@laurentpayot
Copy link

@theryan722 see #5402

@ehsannas
Copy link
Contributor

ehsannas commented Sep 3, 2021

@schmidt-sebastian this seems to be a duplicate of #5402 . Assigning to you as you're looking into that.

@schmidt-sebastian
Copy link
Contributor

@theryan722 Can you share your entire code snippet leading up the call? It would also be helpful if you share debug logs (via setLogLevel('debug')) but I can also obtain them once I can reproduce.

@theryan722
Copy link
Author

Hey @schmidt-sebastian, here's the code before the try catch:

import { FirebaseApp, initializeApp } from 'firebase/app';
import { getFirestore, connectFirestoreEmulator, doc, setDoc, query } from "firebase/firestore";

const firebaseConfig = { MYCONFIGHERE };
const firebaseApp = initializeApp(firebaseConfig);
const firestore = getFirestore(firebaseApp);

connectFirestoreEmulator(firestore, 'localhost', 9152);

@schmidt-sebastian
Copy link
Contributor

I am not able to reproduce. I see "not running after" printed in both Node and in the browser. I will need debug logs to investigate further.

@theryan722
Copy link
Author

theryan722 commented Sep 8, 2021

It only happens if I use the emulator suite, not when connected to the actual firebase project.

@schmidt-sebastian
Copy link
Contributor

Can you try to see if this has in fact been fixed by #5434? You can try by installing firebase@next.

@theryan722
Copy link
Author

Jus tried it, the issue is still there for me :( None of the other workarounds worked either, such as the user who suggested adding a delay after the auth or using long polling. Could it be an issue with the firestore emulator? Everything works fine with I don't use the emulator.

@schmidt-sebastian
Copy link
Contributor

I am not able to reproduce even with the Emulator. It would really help if you shared the Console logs that you can obtain by calling setLogLevel('true').

@theryan722
Copy link
Author

Nothing logs to the console even with setLogLevel('true') or setLogLevel('verbose'). The firestore functions setDoc(), updateDoc(), addDoc(), deleteDoc() just simply to not resolve/return/reject at all, but they do affect the database (e.g. the data IS being added/updated/deleted).

I've tested now with firebase version 9.0.2, and across macOS and Windows.

Screen Shot 2021-09-13 at 3 47 02 PM

@schmidt-sebastian
Copy link
Contributor

Oh sorry. It should be setLogLevel('debug').

@theryan722
Copy link
Author

Gotcha, I set both firebase and firestore log levels to debug. I have attached the resulting file of a fresh page load, with testing of setDoc() and some others.
theryan722-console-logs.log

@schmidt-sebastian
Copy link
Contributor

Thank you for sending these logs. The SDKs seems to function normally, but we do not receive a response from the Emulator when we try to set the document. That caused the setDoc operation to hang.

Assigning this to firebase-tools.

@theryan722
Copy link
Author

Thank you @schmidt-sebastian !

@yuchenshi
Copy link
Member

@theryan722 Would you mind grabbing the logs from the Firestore Emulator? It should be in firestore-debug.log in the directory where you started firebase emulators:start, e.g. your project directory. (Not to be confused with any console logs in your app.)

@theryan722
Copy link
Author

Hey @yuchenshi Here is the log file:
firebase-debug.log

@yuchenshi
Copy link
Member

java.lang.IllegalArgumentException: Invalid pattern. Reason: [112:<eof>] Expected '}' at end of capture expression.

The logs indicate some issues related to function triggers -- please double check the match expressions in your triggers (e.g. onCreate) to make sure the curly braces are correctly closed. Please also check the security rules just in case. Let us know what match expression triggered this and we can work on improving the error.

When in doubt, disable the functions emulator temporarily with firebase emulators:start --only firestore and I believe you'll see the writes go through.

@theryan722
Copy link
Author

Hey, so I corrected the bracket, but was still having issues. I then also upgraded from 9.0.2-2021891633 to the 9.0.2, and it worked with the corrected brackets in the expressions.

Thank you so much! This was driving me crazy,

@firebase firebase locked and limited conversation to collaborators Oct 15, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
testing-sdk testing with emulator v9
Projects
None yet
Development

No branches or pull requests

7 participants