googleapis / googleapis/google-cloud-node

`runTransaction()`: `maxAttempts` not honored when `> MAX_RETRY_ATTEMPTS`

Open
#7,433 2 comments 0 reactions 1 assignee Claimed by @tom-andersen View on GitHub
api: firestore library: nodejs-firestore priority: p3 type: bug
Dominant language
TypeScript
Stars
3.2k
Forks
712
Avg merge
2d 3h
Merged PRs (30d)
99

Description

#### Issue

A call like:

```js
await db.runTransaction(f, { maxAttempts: DB_TRANSACTION_MAX_ATTEMPTS })
```

is not honoring `maxAttempts` when `maxAttempts > MAX_RETRY_ATTEMPTS` (from `ExponentialBackoff` class).
So, setting `maxAttempts: 20` retries only 10 times (which is the current defined value of `MAX_RETRY_ATTEMPTS`).

What is happening is that `maybeBackoff()`:
https://github.com/googleapis/nodejs-firestore/blob/8118d37bf27b49d5e695bf18a9550a37ecc34ca2/dev/src/transaction.ts#L617

is throwing with just an error message when retries hit `MAX_RETRY_ATTEMPTS`:
https://github.com/googleapis/nodejs-firestore/blob/8118d37bf27b49d5e695bf18a9550a37ecc34ca2/dev/src/backoff.ts#L264

so `isRetryableTransactionError(err)` is NOT getting a `GoogleError` error, thus returning `false` and breaking the loop before `maxAttempts` is reached:
https://github.com/googleapis/nodejs-firestore/blob/8118d37bf27b49d5e695bf18a9550a37ecc34ca2/dev/src/transaction.ts#L623

#### Environment details
(Using on Cloud Run Function, gen2)
- OS: Ubuntu 22.04
- Node.js version: 20
- npm version: 10
- `@google-cloud/firestore` version: 7.10.0

Sorry I can't provide a MRE. It just happens when our Firestore database is under heavy load, it's not something I can reproduce at will.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.