Skip to content

fix(firestore): fix empty message reject inside transaction body #9177

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/spotty-bananas-fry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@firebase/firestore': major
---

Fixed a bug where a rejected promise with an empty message in a transaction would cause a timeout. (https://github.com/firebase/firebase-js-sdk/issues/9147)
2 changes: 1 addition & 1 deletion packages/firestore/src/core/transaction_runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export class TransactionRunner<T> {
}

private isRetryableTransactionError(error: Error): boolean {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can make error an optional param to communicate the behavior we have observed. This also supports the change you made below for future readers.

private isRetryableTransactionError(error?: Error): boolean {...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ultranit: Consider using error: Error | undefined rather than error?: Error.

It's somewhat nonsensical to not specify an argument to a function named "isRetryableTransactionError", and defining the parameter as error?: Error allows nonsensical function invocations like this.

In contrast, specifying the argument as error: Error | undefined will cause a TypeScript build error if no argument is specified to the function, but will still allow calling it with an explicit undefined argument.

IMO the latter is the intended use.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (error.name === 'FirebaseError') {
if (error?.name === 'FirebaseError') {
// In transactions, the backend will fail outdated reads with FAILED_PRECONDITION and
// non-matching document versions with ABORTED. These errors should be retried.
const code = (error as FirestoreError).code;
Expand Down
13 changes: 13 additions & 0 deletions packages/firestore/test/integration/api/transactions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,19 @@ apiDescribe('Database transactions', persistence => {
}
);

it('runTransaction with empty message reject inside', () => {
return withTestDb(persistence, async db => {
try {
await runTransaction(db, () => {
return Promise.reject();
});
expect.fail('transaction should fail');
} catch (err) {
expect(err).to.be.undefined;
}
});
});

describe('must return a promise:', () => {
const noop = (): void => {
/* -_- */
Expand Down
Loading