Fix a data race issue with the buffer
This commit is contained in:
parent
654728027b
commit
5488904404
@ -22,10 +22,12 @@ type httpTransportClient struct {
|
|||||||
ht *httpTransport
|
ht *httpTransport
|
||||||
addr string
|
addr string
|
||||||
conn net.Conn
|
conn net.Conn
|
||||||
buff *bufio.Reader
|
|
||||||
dialOpts dialOptions
|
dialOpts dialOptions
|
||||||
r chan *http.Request
|
r chan *http.Request
|
||||||
once sync.Once
|
once sync.Once
|
||||||
|
|
||||||
|
sync.Mutex
|
||||||
|
buff *bufio.Reader
|
||||||
}
|
}
|
||||||
|
|
||||||
type httpTransportSocket struct {
|
type httpTransportSocket struct {
|
||||||
@ -81,6 +83,12 @@ func (h *httpTransportClient) Recv(m *Message) error {
|
|||||||
r = rc
|
r = rc
|
||||||
}
|
}
|
||||||
|
|
||||||
|
h.Lock()
|
||||||
|
defer h.Unlock()
|
||||||
|
if h.buff == nil {
|
||||||
|
return io.EOF
|
||||||
|
}
|
||||||
|
|
||||||
rsp, err := http.ReadResponse(h.buff, r)
|
rsp, err := http.ReadResponse(h.buff, r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -110,11 +118,15 @@ func (h *httpTransportClient) Recv(m *Message) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (h *httpTransportClient) Close() error {
|
func (h *httpTransportClient) Close() error {
|
||||||
h.buff.Reset(nil)
|
err := h.conn.Close()
|
||||||
h.once.Do(func() {
|
h.once.Do(func() {
|
||||||
|
h.Lock()
|
||||||
|
h.buff.Reset(nil)
|
||||||
|
h.buff = nil
|
||||||
|
h.Unlock()
|
||||||
close(h.r)
|
close(h.r)
|
||||||
})
|
})
|
||||||
return h.conn.Close()
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *httpTransportSocket) Recv(m *Message) error {
|
func (h *httpTransportSocket) Recv(m *Message) error {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user