From 0f330dca7e62864d9fa854ad25d26cab17c38fda Mon Sep 17 00:00:00 2001 From: Valentin Trinque Date: Tue, 25 Jan 2022 13:39:04 +0100 Subject: [PATCH] Set Request.GetBody to ensure HTTP2 transport layer can rewind the Request.Body on retry When talking to an HTTP2 server, there are situations where it needs to to "rewind" the Request.Body. To allow this, we have to set up the Request.GetBody function to return a brand new instance of the body. If not set, we can end up with the following error: ``` http2: Transport: cannot retry err [http2: Transport received Server's graceful shutdown GOAWAY] after Request.Body was written; define Request.GetBody to avoid this error ``` Commit : https://sourcegraph.com/github.com/golang/net/-/commit/cffdcf672aee934982473246bc7e9a8ba446aa9b?visible=2 --- rpc/http.go | 1 + 1 file changed, 1 insertion(+) diff --git a/rpc/http.go b/rpc/http.go index 32f4e7d90a259..8640fb8898826 100644 --- a/rpc/http.go +++ b/rpc/http.go @@ -174,6 +174,7 @@ func (hc *httpConn) doRequest(ctx context.Context, msg interface{}) (io.ReadClos return nil, err } req.ContentLength = int64(len(body)) + req.GetBody = func() (io.ReadCloser, error) { return ioutil.NopCloser(bytes.NewReader(body)), nil } // set headers hc.mu.Lock()