Repository navigation
Conversation
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.
Description
A server can send a final response, such as
413 Content Too Large, while Net::HTTP is still uploading the request body. If the connection closes during the upload, the write can raiseECONNRESETbefore Net::HTTP reads that response.Net::HTTP already attempts to read the response after a write-side
EPIPE, but does not do the same forECONNRESET. For POST, the caller receives the reset even when the server’s response remains readable.This change attempts to recover that response without resending the request.
Reproduction
Start a local HTTPS server that records request counts and reads only the request headers. Have it send a complete
413response, then close the underlying TCP socket without consuming the body or sending TLSclose_notify.Use Net::HTTP to POST a large synthetic JSON string to that server. Keep certificate verification enabled and leave
Expect: 100-continuedisabled.Capture raised exceptions, for example with Ruby’s
TracePoint, and repeat until the upload encounters a write-sideECONNRESET. Runs that only encounterEPIPEdo not exercise this gap because Net::HTTP already handles that case.Compare the parent revision with this branch:
413.413response and body when they remain readable.Changes
A private IO wrapper records errors from destination writes, distinguishing them from errors reading streamed or multipart upload sources. Upload-source resets continue to propagate through the existing failure path.
Response recovery requires a final status and complete headers. If those cannot be recovered, the original reset is re-raised. Normal response-body errors, callback errors, and existing retry rules remain unchanged.
After a destination-write reset, the affected connection is closed in
ensure, including when a callback exits nonlocally or a deadline interrupts recovery. Normal reads and the existingEPIPEpath retain their EOF tolerance.The regression tests inject failures deterministically rather than depending on the timing-sensitive network reproduction.
The network reproduction was performed on macOS. Ruby 2.7, Linux, and Windows runtime coverage remains outstanding.