Skip to content

fix: retry events after any transport error, not only a timeout - #80

Open
rfay wants to merge 1 commit into
amplitude:mainfrom
rfay:20261111_rfay_retry_network_errors
Open

rfay wants to merge 1 commit into
amplitude:mainfrom
rfay:20261111_rfay_retry_network_errors

Conversation

@rfay

@rfay rfay commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Summary

A failed send is retried only when the error is a timeout, a 408 or a 5xx. Any other transport error goes to processUnknownError, which hands the batch to the callback and drops it. These include a DNS failure, a refused or reset connection, and a TLS error, such as behind a captive portal or a TLS-intercepting proxy. A client that is briefly offline, or online behind a captive portal, loses every event it tries to send.

This PR retries any *url.Error from http.Client.Do like a timeout, with the same backoff and the same FlushMaxRetries limit. The request may never have reached Amplitude. If it did, the retry is deduplicated by the insert_id that ContextPlugin sets on every event.

Errors that aren't *url.Error keep their current handling. These are a payload that can't be encoded, a request that can't be built, and a response body that can't be read after a 200.

TestNetworkError covers a DNS failure, a refused connection and a TLS certificate error, wrapped the way amplitudeHTTPClient.Send wraps them. It fails without the change. go test -race ./amplitude/... and go vet ./amplitude/... pass.

Found in DDEV, which sends a weekly count of each command it runs (ddev/ddev#9071). Losing one batch there loses a week of counts.

Checklist

  • Does your PR title have the correct title format?
  • Does your PR have a breaking change?: No. Events that used to be dropped on a transport error are now retried, up to FlushMaxRetries, and reach ExecuteCallback only after the last retry.

🤖 Generated with Claude Code

https://claude.ai/code/session_01UrTUMwAzz2CXk6SjcnYYu1


Note

Low Risk
Narrows failure handling to retry transient network issues; behavior for non-url errors is unchanged and duplicates are mitigated by insert_id deduplication.

Overview
Retries any HTTP transport failure instead of only timeouts, 408, and 5xx. Batches that hit a *url.Error from http.Client.Do (DNS failure, connection refused/reset, TLS errors) now follow the same path as timeouts: exponential backoff, FlushMaxRetries, and callback only after the last attempt. Commentary notes Amplitude deduplicates via insert_id if a request actually succeeded.

Adds TestNetworkError for DNS, connection refused, and captive-portal-style TLS errors, using the same wrapped error shape as amplitudeHTTPClient.Send.

Reviewed by Cursor Bugbot for commit cd13f8b. Bugbot is set up for automated code reviews on this repo. Configure here.

A DNS failure, a refused or reset connection, or a TLS error, such as
behind a captive portal, made `processUnknownError` drop the batch with
no retry. These errors mean the request may never have reached
Amplitude, so they are now retried like a timeout, with the same
backoff and `FlushMaxRetries` limit. An event that did arrive is
deduplicated by its `insert_id`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UrTUMwAzz2CXk6SjcnYYu1

This branch has not been deployed

No deployments
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.

2 participants