Skip to content

Commit

Permalink
request: fix intermittent race when verbose and reading the body in d…
Browse files Browse the repository at this point in the history
…ifferent routines (thrasher-corp#1507)

* fix racerooo

* glorious: nits

* close after reading

---------

Co-authored-by: Ryan O'Hara-Reid <[email protected]>
  • Loading branch information
shazbert and Ryan O'Hara-Reid authored Mar 25, 2024
1 parent 3aad665 commit 05dec88
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions exchanges/request/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,20 @@ func (r *Requester) doRequest(ctx context.Context, endpoint EndpointLimit, newRe
log.Debugf(log.RequestSys, "%s request header [%s]: %s", r.name, k, d)
}
log.Debugf(log.RequestSys, "%s request type: %s", r.name, p.Method)
if p.Body != nil {
log.Debugf(log.RequestSys, "%s request body: %v", r.name, p.Body)
if req.GetBody != nil {
bodyCopy, bodyErr := req.GetBody()
if bodyErr != nil {
return bodyErr
}
payload, bodyErr := io.ReadAll(bodyCopy)
err = bodyCopy.Close()
if err != nil {
log.Errorf(log.RequestSys, "%s failed to close request body %s", r.name, err)
}
if bodyErr != nil {
return bodyErr
}
log.Debugf(log.RequestSys, "%s request body: %s", r.name, payload)
}
}

Expand Down

0 comments on commit 05dec88

Please sign in to comment.