From d785811f222c0b3e9c26be4c30171518ea65754d Mon Sep 17 00:00:00 2001 From: fangdingjun Date: Wed, 26 Sep 2018 17:49:32 +0800 Subject: [PATCH] fix race condition on r/w s.request --- conn.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/conn.go b/conn.go index 1540f8a..ec5577b 100644 --- a/conn.go +++ b/conn.go @@ -223,6 +223,9 @@ func (c *Conn) RoundTrip(req *http.Request) (*http.Response, error) { dp.Close() }() } + + s.request = req + select { case res := <-s.resch: /* @@ -230,7 +233,6 @@ func (c *Conn) RoundTrip(req *http.Request) (*http.Response, error) { return nil, fmt.Errorf("http error code %d", res.StatusCode) } */ - s.request = req res.Request = s.request return res, nil case <-c.ctx.Done():