fix(reverseproxy): preserve and rewind request body on dial timeout and error delegation - #5
Open
meridianmindx wants to merge 1 commit into
Conversation
…nd error delegation - Add dialProtectedBody to shield unread incoming request stream from premature closure by net/http.Transport on dial errors - Rewind buffered request bodies (BufferRequests) to offset 0 before returning control to error handlers - Assign safe empty fallback reader for partially consumed streams to prevent http.ErrBodyReadAfterClose - Add complete unit test suite validating dial timeouts, buffered rewind, streaming fallbacks, and protected body lifecycle - Fix undefined syntax token and ensure 100% test pass rate Fixes condoraltidoi32#1
Closed
5 tasks
Author
|
Friendly bump: this has been mergeable for ~4 days with green local verification (body rewind on dial timeout / error delegation). Happy to adjust if you want anything changed. Payout address is in the PR description (Base). |
Author
|
Friendly bump — still MERGEABLE and ready for review/merge when you have a moment. Happy to address any follow-ups quickly. |
Author
|
@condoraltidoi32 Ready for merge when you are — still MERGEABLE and linked to the $10 BountyHub issue. Once merged I can refresh the claim on BountyHub so payout can release. Happy to jump on any last review notes same day. |
Author
|
Hi @condoraltidoi32, friendly bump on PR #5. All unit tests are passing and branch is fully MERGEABLE. Ready to merge whenever you're ready! /claim #1 |
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.
Summary
Fixes #1
This PR ensures that downstream error handlers (
handle_errors, middleware logging, fallback routes) receive a valid, readable, and properly rewoundhttp.Request.Bodywhenreverse_proxyencounters an upstream dial timeout or connection failure.Key Changes
dialProtectedBodyShield:net/http.Transportinstances closereq.Bodywhen dial errors or timeouts occur even before any payload bytes are transmitted.dialProtectedBodywraps the incoming body reader and prevents premature.Close()until payload reads have actually begun.BufferRequestsis enabled, the buffered payload is restored and rewound to offset 0 (io.NopCloser(bytes.NewReader(bufferedBody))) before passing the error downstream.req.Bodyis safely set toio.NopCloser(bytes.NewReader(nil))to eliminate downstreamhttp.ErrBodyReadAfterCloseor nil dereference panics.TestReverseProxyDialTimeoutPreservesRequestBody: Dial failure preserves unbuffered body for error handler.TestReverseProxyBufferedRequestBodyPreservedOnDialFailure: Buffered body rewind.TestReverseProxyPartiallyReadStreamingBodySafeFallback: Graceful empty reader fallback for consumed streams.TestReverseProxyNoBodySafeOnDialFailure: Handling requests without bodies.TestReverseProxySuccessStreamingBody: Clean end-to-end streaming on success.TestDialProtectedBodyLifecycle: Lifecycle isolation test.Verification