Skip to content

Commit

Permalink
fix sync pool data race: deep copy
Browse files Browse the repository at this point in the history
  • Loading branch information
zhongdalu-trechina committed Mar 21, 2023
1 parent 9943eab commit 5d5fd98
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 5d5fd98

Please sign in to comment.