http2: log the correct error when retrying in (*Transport).RoundTripOpt

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 <gobot@golang.org>
Run-TryBot: Bryan Mills <bcmills@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
diff --git a/http2/transport.go b/http2/transport.go
index c9e1115..f965579 100644
--- a/http2/transport.go
+++ b/http2/transport.go
@@ -560,10 +560,11 @@
 		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))
@@ -572,7 +573,7 @@
 				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()