-
Notifications
You must be signed in to change notification settings - Fork 370
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
DocumentReference.create()
keeps trying to create an already existing document, leading to a hang in functions
#2587
Comments
I found a few problems with this issue:
|
In addition, performing this in a transaction will eventually fail and terminate the function. exports.runMeTwice = onRequest(async (_, res) => {
try {
const firestore = defaultFirestore();
await firestore.runTransaction(async (txn) => {
txn.create(firestore.collection("test").doc("smt"), {});
})
logger.log("Created");
} catch (error) {
logger.log(error);
} finally {
res.end();
}
}); |
Hi @jellynoone , I will take a look at this and get back to you. |
While investigating, there are some things can be tried as a workaround:
|
This is the code I used to reproduce the issue against production, it throws
Are you testing against production or emulator? |
I'm testing this against the emulator. Did you try with the provided example? Tested this again against the emulator, without |
@cherylEnkidu Did you perhaps have a chance to reevaluate based on the additional information provided? |
Hi @jellynoone , I will continue the investigation this week, and I will reply the ticket as soon as I get any updates :) |
Hi @cherylEnkidu were you able to take a look? |
Hi @jellynoone , Thanks for the waiting. I tried the same code you provided, but the process never hangs. Could you please provided a small repo app? |
Attaching a small repro app. Additional notes:
|
@cherylEnkidu Attaching a video of the bug being reproduced. Bug.mp4In the video I'm using In addition, in the video I'm calling |
@cherylEnkidu Do you need more information or anything else? Were you able to reproduce the issue? |
Hi @jellynoone , Thank you for your inputs! I will take a look at the code provided and get back to you. |
Hi @jellynoone , I have successfully reproduce the issue, while investigating, you may consider removing |
@cherylEnkidu Thank you for getting back to me. Unfortunately disabling While the issue can be circumvented, I can imagine that people who don't do this manually and rely on the firebase-admin package to fail when an existing document is attempted to be created again, and allow user supplied ids, might be exposing themselves to a resources exhaustion attack. So to me this seems like a high priority issue. |
When using preferRest, the Firestore endpoint is returning status code 409 when the document already exists. It's also returning 409 when the server aborted the request. The SDK cannot distinguish these two conditions and it is retrying the request, which is appropriate for aborted requests. Unfortunately, I don't have a workaround for this at the moment, other than what you've suggested. We are looking into it. Googlers see b/352387470 |
@MarkDuckworth Out of curiosity, couldn't the Attaching the debugger, the raw response received looks something like this: This is where the exception is first thrown by the google-gax package at: build/src/fallbackRest.json#decodeResponse. When this raw response is processed however, the status is dropped from the error object. However, all the information seems to be sent already it is just that the Additionally, it seems the |
[READ] Step 1: Are you in the right place? ✅
[REQUIRED] Step 2: Describe your environment
MacOS 14.5
functions
,firestore
v18.20.3
10.7.0
[REQUIRED] Step 3: Describe the problem
Steps to reproduce:
firebase init
functions
andfirestore
firebase emulators:start --inspect-functions --project demo-me
http://127.0.0.1:5001/demo-me/us-central1/runMeTwice
in browserRelevant Code:
Expected behavior
The second time the function is ran, it should fail.
Actual behavior
The first time the function is run the document is created. The second time, the function never completes.
Additionally, attaching to the node process, it seems the creation process keeps getting retried even though it should fail.
The text was updated successfully, but these errors were encountered: