项目上遇到一个问题,在json解码接口A返回的数据时,发现竟然解码的是接口B返回的数据,因为项目使用的是fasthttp,怀疑是并发情况下数据被overlap,一查还真是。
fasthttp-repo
响应体数据在并发情况下被overlap的相关issue
相关代码:
http.go的func (resp *Response) Body() []byte函数,在323行左右
// Body returns response body.
//
// The returned value is valid until the response is released,
// either though ReleaseResponse or your request handler returning.
// Do not store references to returned value. Make copies instead.
func (resp *Response) Body() []byte {
if resp.bodyStream != nil {
bodyBuf := resp.bodyBuffer()
bodyBuf.Res