Repository navigation
Don't retry a request whose body comes from an IO - #371
Merged
Merged
Conversation
A retry re-sends the same request object. When the body comes from body_stream, or from an IO in form data, the first attempt may have read that IO, so the retry sends only what is left. With chunked framing that remainder is a complete message, and the server can store a truncated or empty body while the client sees a success response. Never retry such requests automatically; raise the original error so the caller can rewind the IO and retry itself.
IOIO
orien
marked this pull request as ready for review
November 27, 2026 06:40
Contributor
Author
|
/cc @mame |
mame
approved these changes
Nov 27, 2026
mame
left a comment
Member
There was a problem hiding this comment.
Thank you! Retrying only when the IO hasn't been read yet would make the behavior harder to predict, so let's consider it when someone actually needs it.
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.
Context
Net::HTTPautomatically retries an idempotent request after a connection error (max_retries, 1 by default). The retry sends the same request object again.When the request body comes from an
IO, the first attempt may already have read it, so the retry sends only what is left. With chunked transfer encoding the leftover is still a well-formed body, so the server accepts it and can store a truncated or empty body while the client sees a success response.Change
A request whose body comes from an
IOis no longer retried automatically. The original error is raised, so the caller can rewind theIOand retry itself.body_stream=and anyIOvalue given toset_form.IOvalues, or no body are retried as before.max_retries=documentation describes the new rule.Considerations
IOwas read. A request that fails before any body byte is sent, for example on a stale keep-alive connection, was retried safely before and now raises.IOwas actually read would keep those retries, at the cost of new state on the request object. I kept the smaller change; I'm happy to switch if that is preferred.