Skip to content

feat(firestore): add retry support for WriteBatch commit#188

Open
developerjamiu wants to merge 2 commits intoinvertase:mainfrom
developerjamiu:retry-support
Open

feat(firestore): add retry support for WriteBatch commit#188
developerjamiu wants to merge 2 commits intoinvertase:mainfrom
developerjamiu:retry-support

Conversation

@developerjamiu
Copy link

@developerjamiu developerjamiu commented Mar 11, 2026

Related Issues

Fixes #63

Problem

Standalone write operations (set, update, create, delete) use WriteBatch._commit() to send a single HTTP request to Firestore. If the server returns a transient error such as UNAVAILABLE, RESOURCE_EXHAUSTED, or ABORTED, the operation fails immediately with no retry — even though the same request sent moments later would succeed.

The retry infrastructure (ExponentialBackoff, commitRetryCodes) was already ported from the Node.js SDK but never wired into the commit path.

Solution

Added a retry loop to WriteBatch._commit() using the existing ExponentialBackoff and _maybeBackoff() utilities, matching the pattern already used in _runTransaction().

Retry codes follow the Node.js SDK (write-batch.ts line 443): ABORTED + commitRetryCodes (RESOURCE_EXHAUSTED, UNAVAILABLE).

Transaction commits are excluded from this retry loop — they pass a transactionId and are already retried at the transaction layer.

Changes

  • write_batch.dart: retry loop in _commit() for standalone commits
  • write_batch_test.dart: 5 tests covering retry and non-retry paths

Checklist

Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]).

  • I have updated the CHANGELOG.md of the relevant packages.
    Changelog files must be edited under the form:
## Unreleased minor

- Added retry support for `WriteBatch.commit()` on transient errors (`ABORTED`, `UNAVAILABLE`, `RESOURCE_EXHAUSTED`). (thanks to @developerjamiu)
  • If this contains new features or behavior changes,
    I have updated the documentation to match those changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support retry on document set()

1 participant