Skip to content

Adds a setting to retry transient errors - #9

Merged
ehannes merged 1 commit into
mainfrom
retry-transient-errors
Nov 17, 2026
Merged

ehannes merged 1 commit into
mainfrom
retry-transient-errors

Conversation

@ehannes

@ehannes ehannes commented Nov 17, 2026

Copy link
Copy Markdown
Member

Every failed response went to the authentication's on_rejected, which decided whether to retry. That left retrying a 429 or 5xx to the auth strategy, so a consumer that wanted it had to put a retry policy inside its authentication class.

With retry_transient_errors on, the retry loop handles transient errors itself and on_rejected only sees the other failures. A 429 means the server did not act on the request, so it is retried for any method. A 5xx can arrive after the server already acted, so it is retried only on GET, PUT and DELETE; on POST it goes to on_rejected, since retrying a creating POST could create twice. Timeouts and dropped connections (Faraday::TimeoutError and ConnectionFailed) are retried on the same terms as a 5xx. They have no response for on_rejected, so without the setting they are raised as before.

Every retry waits for Retry-After, which a 503 commonly carries as well as a 429. It is read in base 10, so "010" is not octal, and as an HTTP date when it is not a number; without it the wait is 1 second. One asking for more than 10 seconds raises at once, as retrying before the server allows would only use up the retries on further 429s.

It is off by default: a strategy whose on_rejected raises gets no retries today and would start retrying, and PUT and DELETE are only safe to repeat on APIs that implement them idempotently.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

The POST rejection-callback path bypasses the Retry-After delay and 10-second limit, allowing a premature retry, and the HTTP-date timing test can fail across a second boundary.

2 open issues
What changed in this PR

Adds opt-in transient-error retries to RestEasy’s HTTP request lifecycle, reducing the need for retry policies in authentication strategies.

Changes:

  • Adds retry_transient_errors, disabled by default, with method-aware handling of HTTP failures and network errors.
  • Introduces Retry-After parsing, a default delay, and a maximum wait.
  • Documents the retry policy and adds coverage for retries, limits, and authentication fallback.
File Description
spec/​rest_easy/​resource/​http_spec.rb Tests transient retries, delays, method restrictions, and fallback behavior.
README.md Documents the setting and retry lifecycle.
lib/​rest_easy/​settings.rb Defines the disabled-by-default setting.
lib/​rest_easy.rb Implements transient-error handling and retry-delay parsing.
CHANGELOG.md Records the new setting and its behavior.

Review effort: Balanced

Comment thread lib/rest_easy.rb Resolved
Comment thread spec/rest_easy/resource/http_spec.rb Resolved
Every failed response went to the authentication's on_rejected, which
decided whether to retry. That left retrying a 429 or 5xx to the auth
strategy, so a consumer that wanted it had to put a retry policy inside
its authentication class.

With retry_transient_errors on, the retry loop handles transient errors
itself and on_rejected only sees the other failures. A 429 means the
server did not act on the request, so it is retried for any method. A
5xx can arrive after the server already acted, so it is retried only on
GET, PUT and DELETE; on POST it goes to on_rejected, since retrying a
creating POST could create twice. Timeouts and dropped connections
(Faraday::TimeoutError and ConnectionFailed) are retried on the same
terms as a 5xx. They have no response for on_rejected, so without the
setting they are raised as before.

Every retry waits for Retry-After, which a 503 commonly carries as well
as a 429. It is read in base 10, so "010" is not octal, and as an HTTP
date when it is not a number; without it the wait is 1 second. One
asking for more than 10 seconds raises at once, as retrying before the
server allows would only use up the retries on further 429s.

It is off by default: a strategy whose on_rejected raises gets no
retries today and would start retrying, and PUT and DELETE are only
safe to repeat on APIs that implement them idempotently.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ehannes
ehannes force-pushed the retry-transient-errors branch from 4bf9294 to f6c4d8c Compare November 17, 2026 13:34
@ehannes
ehannes merged commit 2c817e9 into main Nov 17, 2026
3 checks passed
@ehannes
ehannes deleted the retry-transient-errors branch November 17, 2026 13:38
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