-
Notifications
You must be signed in to change notification settings - Fork 164
runTransaction potentially returning the wrong resolved promise when retrying #110
Description
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,
});
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!