Skip to content

Commit 43a4efb

Browse files
committed
fix: retry on GOAWAY errors when using cached HTTP/2 connections
RoundTripOnlyCachedConn bypasses the retry loop in RoundTripOpt, so GOAWAY and other retryable errors were returned directly to callers. Now we check CanRetryError before returning, allowing retryable errors to fall through and create a new connection. Changes: - Export canRetryError as CanRetryError - Check CanRetryError in roundTrip when RoundTripOnlyCachedConn fails
1 parent 247aa96 commit 43a4efb

2 files changed

Lines changed: 3 additions & 3 deletions

File tree

internal/http2/transport.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ var (
527527
// It returns either a request to retry (either the same request, or a
528528
// modified clone), or an error if the request can't be replayed.
529529
func shouldRetryRequest(req *http.Request, err error) (*http.Request, error) {
530-
if !canRetryError(err) {
530+
if !CanRetryError(err) {
531531
return nil, err
532532
}
533533
// If the Body is nil (or http.NoBody), it's safe to reuse
@@ -558,7 +558,7 @@ func shouldRetryRequest(req *http.Request, err error) (*http.Request, error) {
558558
return nil, fmt.Errorf("http2: Transport: cannot retry err [%v] after Request.Body was written; define Request.GetBody to avoid this error", err)
559559
}
560560

561-
func canRetryError(err error) bool {
561+
func CanRetryError(err error) bool {
562562
if err == errClientConnUnusable || err == errClientConnGotGoAway {
563563
return true
564564
}

transport.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -944,7 +944,7 @@ func (t *Transport) roundTrip(req *http.Request) (resp *http.Response, err error
944944

945945
if scheme == "https" && t.forceHttpVersion != h1 {
946946
resp, err := t.t2.RoundTripOnlyCachedConn(req)
947-
if err != h2internal.ErrNoCachedConn {
947+
if err != h2internal.ErrNoCachedConn && !h2internal.CanRetryError(err) {
948948
return resp, err
949949
}
950950
req, err = rewindBody(req)

0 commit comments

Comments
 (0)