From e187266de6db1c8ffd1426272b7b42448657c70e Mon Sep 17 00:00:00 2001 From: Erik Dubbelboer Date: Sun, 19 Feb 2017 06:44:22 +0000 Subject: [PATCH] Prevent bugs caused by multiple Close See: https://github.com/golang/go/issues/19186 When the body isn't fully read and Close is called multiple times we put the same buffer in the pool multiple times causing it to be reused by multiple goroutines at the same time. --- buffer/pool.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/buffer/pool.go b/buffer/pool.go index 0655b4b..bc936c1 100644 --- a/buffer/pool.go +++ b/buffer/pool.go @@ -252,6 +252,8 @@ func (r *readCloser) Close() error { for _, buf := range r.bufs { putBuf(buf) } + // In case Close gets called multiple times. + r.bufs = nil return nil }