Skip to content

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

Merged
demolaf merged 1 commit intofirebase:mainfrom
developerjamiu:retry-support
Apr 16, 2026
Merged

feat(firestore): add retry support for WriteBatch commit#188
demolaf merged 1 commit intofirebase:mainfrom
developerjamiu:retry-support

Conversation

@developerjamiu
Copy link
Copy Markdown
Contributor

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

Comment thread packages/dart_firebase_admin/lib/src/google_cloud_firestore/write_batch.dart Outdated
@developerjamiu developerjamiu force-pushed the retry-support branch 5 times, most recently from 4afb249 to 42ef2b3 Compare April 16, 2026 10:50
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Apr 16, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (main@63ba6a4). Learn more about missing BASE report.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #188   +/-   ##
=======================================
  Coverage        ?   74.59%           
=======================================
  Files           ?      105           
  Lines           ?     6801           
  Branches        ?        0           
=======================================
  Hits            ?     5073           
  Misses          ?     1728           
  Partials        ?        0           
Flag Coverage Δ
unittests 74.59% <100.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment thread packages/google_cloud_firestore/CHANGELOG.md
@demolaf demolaf merged commit ba17c8b into firebase:main Apr 16, 2026
12 checks passed
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()

3 participants