Skip to content

Commit

Permalink
fix sync pool data race: deep copy (#635)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhongdalu-trechina committed Mar 21, 2023
1 parent f55f417 commit b34a3ad
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion middleware.go
Expand Up @@ -169,7 +169,9 @@ func createHTTPRequest(c *Client, r *Request) (err error) {
r.RawRequest, err = http.NewRequest(r.Method, r.URL, nil)
}
} else {
r.RawRequest, err = http.NewRequest(r.Method, r.URL, r.bodyBuf)
// fix data race: must deep copy.
bodyBuf := bytes.NewBuffer(append([]byte{}, r.bodyBuf.Bytes()...))
r.RawRequest, err = http.NewRequest(r.Method, r.URL, bodyBuf)
}

if err != nil {
Expand Down

0 comments on commit b34a3ad

Please sign in to comment.