Skip to content

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

Open
developerjamiu wants to merge 1 commit intofirebase:mainfrom
developerjamiu:retry-support
Open

feat(firestore): add retry support for WriteBatch commit#188
developerjamiu wants to merge 1 commit intofirebase:mainfrom
developerjamiu:retry-support

Conversation

@developerjamiu
Copy link
Copy Markdown

@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.

Copy link
Copy Markdown
Member

@demolaf demolaf left a comment

Choose a reason for hiding this comment

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

Hi @developerjamiu thanks for opening this PR.

Looks good, only thing left to do is pull the most recent changes and pending comment. Ready to approve and merge after that, thanks.

@developerjamiu developerjamiu force-pushed the retry-support branch 3 times, most recently from e68777e to ba3d499 Compare April 14, 2026 18:42
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()

2 participants