Skip to content

Commit

Permalink
http2: log the correct error when retrying in (*Transport).RoundTripOpt
Browse files Browse the repository at this point in the history
On the shouldRetryRequest path, err is invariantly nil, and therefore
meaningless to log with vlogf. Instead, log the original error returned
by the call to cc.RoundTrip.

For golang/go#59155.

Change-Id: I82c00a6033d0e92c28a5ccf60a87eec1c8b41886
Reviewed-on: https://go-review.googlesource.com/c/net/+/477876
TryBot-Result: Gopher Robot <[email protected]>
Run-TryBot: Bryan Mills <[email protected]>
Auto-Submit: Bryan Mills <[email protected]>
Reviewed-by: Damien Neil <[email protected]>
  • Loading branch information
Bryan C. Mills authored and gopherbot committed Mar 20, 2023
1 parent 9f24bb4 commit 6960703
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions http2/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -560,10 +560,11 @@ func (t *Transport) RoundTripOpt(req *http.Request, opt RoundTripOpt) (*http.Res
traceGotConn(req, cc, reused)
res, err := cc.RoundTrip(req)
if err != nil && retry <= 6 {
roundTripErr := err
if req, err = shouldRetryRequest(req, err); err == nil {
// After the first retry, do exponential backoff with 10% jitter.
if retry == 0 {
t.vlogf("RoundTrip retrying after failure: %v", err)
t.vlogf("RoundTrip retrying after failure: %v", roundTripErr)
continue
}
backoff := float64(uint(1) << (uint(retry) - 1))
Expand All @@ -572,7 +573,7 @@ func (t *Transport) RoundTripOpt(req *http.Request, opt RoundTripOpt) (*http.Res
timer := backoffNewTimer(d)
select {
case <-timer.C:
t.vlogf("RoundTrip retrying after failure: %v", err)
t.vlogf("RoundTrip retrying after failure: %v", roundTripErr)
continue
case <-req.Context().Done():
timer.Stop()
Expand Down

0 comments on commit 6960703

Please sign in to comment.