From 2650a2f264fddaccc0899eaf0874ddbebc371f1a Mon Sep 17 00:00:00 2001 From: Vicent Marti Date: Tue, 22 Jun 2021 17:30:15 +0200 Subject: [PATCH] internal/transport: do not mask ConnectionError PR #4316 updates the http2Client `Close` method so it can append additional debug information about prior GOAWAY messages before this connection was closed. However, it is not safe to do this in the general case, as the original error is propagated through the connection's `Stream` via a `recvMsg`, and read later on. If the additional metadata is appended by wrapping the error with `fmt.Errorf`, downstream clients will not be able to detect meaningful error conditions (such as `io.EOF`) or the temporarity of the error. Fix this by properly wrapping the original error with `connectionErrorf` like it is done for all the other errors in the client. --- internal/transport/http2_client.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/internal/transport/http2_client.go b/internal/transport/http2_client.go index 119f01e3ebc..dd52454d0b8 100644 --- a/internal/transport/http2_client.go +++ b/internal/transport/http2_client.go @@ -878,7 +878,13 @@ func (t *http2Client) Close(err error) { // for understanding the root cause for this connection to be closed. _, goAwayDebugMessage := t.GetGoAwayReason() if len(goAwayDebugMessage) > 0 { - err = fmt.Errorf("closing transport due to: %v, received prior goaway: %v", err, goAwayDebugMessage) + tmpErr := true + originalErr := err + if ce, ok := err.(ConnectionError); ok { + tmpErr = ce.Temporary() + originalErr = ce.Origin() + } + err = connectionErrorf(tmpErr, originalErr, "closing transport due to: %v, received prior goaway: %v", originalErr, goAwayDebugMessage) } // Notify all active streams. for _, s := range streams {