Retry transient HTTP errors (502/503/504) and network errors#155
Open
0ca wants to merge 1 commit into
Open
Conversation
When Terraform refreshes state for many resources in parallel, the Doppler API occasionally returns transient 502 errors from Cloudflare (HTML error pages, ~6443 bytes) or transient network errors (EOF, connection reset). Previously, non-JSON error responses had RetryAfter set to nil, causing the retry loop in PerformRequestWithRetry to exit immediately. Similarly, only net.Error timeouts were retried, while EOF and connection reset errors failed permanently. This change: - Adds retry with 1s backoff for 502, 503, 504 status codes regardless of response content type (these are typically infrastructure-level transient errors from load balancers/proxies) - Extends network error retries to cover EOF and connection reset errors, not just timeouts Reproduced by running parallel API requests matching the Terraform provider's exact HTTP client config (DisableKeepAlives: true, new client per request). Captured a Cloudflare 502 with Proxy-Status: error=http_response_incomplete, confirming the origin occasionally sends incomplete responses under load. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Problem
When Terraform refreshes state for many Doppler resources in parallel (~60+ resources), the API occasionally returns:
The current code at
api.go:185returns these errors withRetryAfter: nil, causing the retry loop to exit immediately. The error surfaces as:Root Cause
Two issues in
PerformRequest():RetryAfteris never set, so the retry loop gives up immediatelynet.Errortimeouts trigger a retry. EOF and connection reset errors getRetryAfter: niland fail permanentlyReproduction
We reproduced this using a Go program that mirrors the provider's exact HTTP client configuration (
DisableKeepAlives: true, newhttp.Clientper request, 30s timeout). Running 60 concurrent requests every 3 seconds:Proxy-Status: Cloudflare-Proxy;error=http_response_incomplete— the origin sent an incomplete responseFix
isTransientStatusCode(): Returns true for 502, 503, 504isTransientError(): Returns true for timeouts, EOF, connection reset, connection refusedRetryAfterfor transient cases, enabling the existing retry loop (up to 10 attempts with 1s backoff)What this does NOT change
MAX_RETRIES(10) unchangedDisableKeepAlives, timeouts) unchangedTest plan
go build ./...compiles cleango test ./...passes (no existing tests broken)🤖 Generated with Claude Code