Open jellynoone opened 1 month ago
I found a few problems with this issue:
In addition, performing this in a transaction will eventually fail and terminate the function. However, attaching the debugger it shows, the transaction is still attempted multiple times. This seems incorrect.
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.
@jellynoone
While investigating, there are some things can be tried as a workaround:
DocumentReference.create()
calls bulkWriter
internally. You can try to use bulkWriter
and config the retry optionThis is the code I used to reproduce the issue against production, it throws Document already exists
successfully.
const ref = randomCol.doc();
await ref.create({});
const snap1 = await ref.get();
await ref.create({});
Are you testing against production or emulator?
I'm testing this against the emulator. Did you try with the provided example?
I think the preferRest: true,
configuration option might be significant.
Tested this again against the emulator, without preferRest
the function completes with an error. With preferRest
the function hangs.
@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.
https://github.com/firebase/firebase-admin-node/assets/77585130/d4bba6c7-4385-4165-bf79-3c677dce04ed
In the video I'm using firebase emulators:start --project demo-me
to start the emulators without needing a real project. However, I tested this with a live Firestore instance and emulated functions and observed the same bug.
In addition, in the video I'm calling curl
instead of the browser to make the process more streamlined.
@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.
[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.