Skip to content

Commit abd49a6

Browse files
rpc: set Request.GetBody for client requests (#24292)
When talking to an HTTP2 server, there are situations where it needs 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 See this commit for more information: https://sourcegraph.com/github.com/golang/net/-/commit/cffdcf672aee934982473246bc7e9a8ba446aa9b?visible=2
1 parent a988550 commit abd49a6

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

rpc/http.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ func (hc *httpConn) doRequest(ctx context.Context, msg interface{}) (io.ReadClos
181181
return nil, err
182182
}
183183
req.ContentLength = int64(len(body))
184+
req.GetBody = func() (io.ReadCloser, error) { return ioutil.NopCloser(bytes.NewReader(body)), nil }
184185

185186
// set headers
186187
hc.mu.Lock()

0 commit comments

Comments
 (0)