Conversation
Body#each rewinds an IO source after IO.copy_stream has sent it, so the request can be sent again. When a write fails partway, for example because the server reset the connection mid-upload, copy_stream raises and the rewind is skipped. The IO stays where the failed write stopped, so a retried request, such as one sent by `.retriable`, sends only the remainder while its Content-Length still declares the full size. The server then waits for the missing bytes until the read times out. Writer#send_request rescues EPIPE, so the same happens when the write fails with a broken pipe and the request fails later, reading the response. Rewind in an ensure, so the IO is back at its start however the copy ends.
This branch has not been deployed
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.
Body#eachrewinds an IO body afterIO.copy_streamhas sent all of it. When a write fails partway,copy_streamraises and the rewind is skipped, so the IO stays where the failed write stopped. A retried request, e.g. from.retriable, then sends only the remainder under the originalContent-Length, and the server waits for the missing bytes until the read times out.Origin that resets connection 1 after reading about 64 KiB of the body, and counts body bytes on connection 2. Client:
HTTP.timeout(connect: 2, write: 5, read: 2).retriable(tries: 2, delay: 0).post(url, body: 8 MiB):StringIObody (2 runs)HTTP::OutOfRetriesError, read timed out after 2 sStringbodyStringIObody (3 runs)On main the retry followed a
SocketWriteErrorin one run and aSocketReadErrorin the other.Writer#send_requestrescuesEPIPE, so a broken pipe only surfaces when the response is read, but the rewind was skipped on both paths.The fix moves the copy into
copy_io, which rewinds in anensure.Body#sizealready reports the IO's full size asContent-Length, so rewinding to the start matches what the header declares. Pipes still can't be rewound (rewindrescuesESPIPEas before), so a retried pipe body still sends only what's left. That's unchanged.The new test lets the first 16 KiB chunk through, fails the second with
EPIPE, and checks that the nexteachyields the whole body. It fails on main.mutant run --since main: 76/76 mutations killedbody.rbthe new test fails there tooRepro script