Skip to content

Commit

Permalink
rpc: set Request.GetBody for client requests (ethereum#24292)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ValentinTrinque authored and jagdeep sidhu committed Jan 28, 2022
1 parent 3158e1f commit 1f6a0f9
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions rpc/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,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()
Expand Down

0 comments on commit 1f6a0f9

Please sign in to comment.