From 096dd3ff75619ee88721eaa559bbf88924449bc2 Mon Sep 17 00:00:00 2001 From: Roy Lee Date: Tue, 24 May 2022 00:00:31 -0700 Subject: [PATCH] [lbry] rpcclient: fix http response resource leaking --- rpcclient/infrastructure.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/rpcclient/infrastructure.go b/rpcclient/infrastructure.go index 943732ff..9b93d739 100644 --- a/rpcclient/infrastructure.go +++ b/rpcclient/infrastructure.go @@ -803,6 +803,7 @@ func (c *Client) handleSendPostMessage(jReq *jsonRequest) { time.Sleep(backoff) continue } + defer httpResponse.Body.Close() break } if err != nil { @@ -810,9 +811,8 @@ func (c *Client) handleSendPostMessage(jReq *jsonRequest) { return } - // Read the raw bytes and close the response. + // Read the raw bytes from the response. respBytes, err := ioutil.ReadAll(httpResponse.Body) - httpResponse.Body.Close() if err != nil { err = fmt.Errorf("error reading json reply: %v", err) jReq.responseChan <- &Response{err: err} @@ -1386,6 +1386,7 @@ func dial(config *ConnConfig) (*websocket.Conn, error) { // cases above apply. return nil, errors.New(resp.Status) } + resp.Body.Close() return wsConn, nil }