Skip to content
This repository was archived by the owner on Mar 4, 2026. It is now read-only.
This repository was archived by the owner on Mar 4, 2026. It is now read-only.

runTransaction potentially returning the wrong resolved promise when retrying #110

@fcaneto

Description

@fcaneto

Hi,

apologies for not opening a complete issue (with instructions for reproducing it) but I assumed that opening a discussion could help us pinpoint a potential problem quicker.

When implementing a counter-like feature, I noticed that, when a transaction retries, the returned promise has the value of the first try, instead of the last.

This is the line that seems incorrect (the recursive call to runTransaction):

return this.runTransaction(updateFunction, {
              previousTransaction: transaction,
              maxAttempts: attemptsRemaining,
            });

https://github.com/googleapis/nodejs-firestore/blob/master/src/index.js#L496

Changing this line to the following solved my issue:

result = this.runTransaction(updateFunction, {
              previousTransaction: transaction,
              maxAttempts: attemptsRemaining,
            });
return result;

This guarantees that the current execution of runTransaction returns (at line 510) the promise from the previous execution when unstacking the calls.

I wasn't sure how I could quickly add a test for it in a repository fork, so I decided to open this issue to clear things up before any next steps.

Let me know if the issue is still unclear and I'll provide a test project that illustrates it. Also let me know if you think this is not an issue at all.

Thanks!

Metadata

Metadata

Labels

🚨This issue needs some love.api: firestoreIssues related to the googleapis/nodejs-firestore API.triage meI really want to be triaged.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions