Skip to content

Fix RoundTripper returning both response and error - #299

Open
BetterAndBetterII wants to merge 1 commit into
hashicorp:mainfrom
BetterAndBetterII:fix/roundtrip-response-and-error
Open

Fix RoundTripper returning both response and error#299
BetterAndBetterII wants to merge 1 commit into
hashicorp:mainfrom
BetterAndBetterII:fix/roundtrip-response-and-error

Conversation

@BetterAndBetterII

Copy link
Copy Markdown

Summary

RoundTripper.RoundTrip returned both a non-nil *http.Response and an error when Client.Do produced a *url.Error (for example redirect exhaustion with PassthroughErrorHandler). That violates the http.RoundTripper contract and causes net/http.Client to log RoundTripper returned a response & error; ignoring response.

On error, close any response body and return nil, err, still unwrapping *url.Error so the outer client does not double-wrap.

Test plan

  • go test -count=1 -race ./...
  • New tests cover RoundTrip alone and via StandardClient() so the net/http log line does not appear

Fixes #179

On *url.Error from Client.Do (e.g. redirect stop with PassthroughErrorHandler),
RoundTrip used to return the response alongside the unwrapped error. That
violates http.RoundTripper and makes net/http.Client log that it is ignoring
the response. Close any body and return nil with the error instead.

Fixes hashicorp#179
@BetterAndBetterII
BetterAndBetterII requested a review from a team as a code owner September 4, 2026 21:26
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.

RoundTripper returns a non-nil response and error

1 participant