Skip to content

Commit e482896

Browse files
DavyJohnesmaxatome
authored andcommitted
fix: avoid data race when closing body
1 parent c977145 commit e482896

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

response.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,7 @@ type lenReadSeeker interface {
741741
type dummyReadCloser struct {
742742
orig any // string or []byte
743743
body lenReadSeeker // instanciated on demand from orig
744+
mu sync.Mutex
744745
}
745746

746747
// copy returns a new instance resetting d.body to nil.
@@ -771,6 +772,9 @@ func (d *dummyReadCloser) Read(p []byte) (n int, err error) {
771772
}
772773

773774
func (d *dummyReadCloser) Close() error {
775+
d.mu.Lock()
776+
defer d.mu.Unlock()
777+
774778
d.setup()
775779
d.body.Seek(0, io.SeekEnd) //nolint: errcheck
776780
return nil

0 commit comments

Comments
 (0)