Skip to content

fix(firestore): retry reads on transient connection-closed errors - #294

Merged
demolaf merged 3 commits into
mainfrom
fix/firestore-retry-reads
Jul 3, 2026
Merged

demolaf merged 3 commits into
mainfrom
fix/firestore-retry-reads

Conversation

@demolaf

@demolaf demolaf commented Jul 1, 2026

Copy link
Copy Markdown
Member

Fixes #291.

under high concurrency, Query.get(), AggregateQuery.get(), Transaction.getQuery(), and Transaction.getAggregateQuery() could throw ClientException: Connection closed before full header was received — a known dart:io HttpClient keep-alive race with no client-side fix except retrying. Added a shared retryOnConnectionError helper that retries with backoff when no partial results were received yet and the read isn't inside an active transaction.

@demolaf
demolaf marked this pull request as draft July 1, 2026 16:12
@github-actions

github-actions Bot commented Jul 1, 2026 •

Copy link
Copy Markdown

Coverage Report

✅ Coverage 75.48% meets 40% threshold

Total Coverage: 75.48%
Lines Covered: 5208/6900

Package Breakdown

Package Coverage
google_cloud_firestore 78.68%
firebase_admin_sdk 72.66%

Minimum threshold: 40%

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request implements retries with exponential backoff on transient connection errors (http.ClientException) for Firestore query and aggregation reads, adding corresponding unit tests. The review feedback points out that the retry helper introduces an unnecessary delay on the first attempt and loses the original stack trace. Additionally, the query and aggregation readers should reset the retrieved transaction ID at the start of each attempt to ensure clean state isolation between retries.

@demolaf
demolaf force-pushed the fix/firestore-retry-reads branch from 9b41cd7 to 93e825b Compare July 1, 2026 16:24
@demolaf
demolaf marked this pull request as ready for review July 2, 2026 10:44
@demolaf
demolaf force-pushed the fix/firestore-retry-reads branch from f6c7f9a to 227c221 Compare July 2, 2026 10:45
@demolaf
demolaf requested a review from Lyokone July 2, 2026 10:56
results[entry.key] = value.doubleValue;
} else if (value.nullValue != null) {
results[entry.key] = null;
return retryOnConnectionError(() async {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

https://pub.dev/packages/retry would rather use this Google package that actually does exponential backoff

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

i'll look into it, there's already a pre-existing backoff implementation the retryOnConnectionError just wraps it, see

@demolaf
demolaf force-pushed the fix/firestore-retry-reads branch from 973e26e to 0cc084a Compare July 3, 2026 10:04
@demolaf
demolaf merged commit 0eb09ac into main Jul 3, 2026
21 checks passed
@demolaf
demolaf deleted the fix/firestore-retry-reads branch July 3, 2026 12:02
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.

ClientException: Connection closed before full header was received

2 participants