From 48461b67b1d9715bd7f83fd0bcbc399d6712187f Mon Sep 17 00:00:00 2001 From: "mission.liao" Date: Wed, 28 Dec 2022 20:44:35 +0800 Subject: [PATCH] fix: panic when the response is nil This change is copied from btcd@master(718d268) directly --- rpcclient/infrastructure.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/rpcclient/infrastructure.go b/rpcclient/infrastructure.go index f2b6b34dde..ecd25e8d2e 100644 --- a/rpcclient/infrastructure.go +++ b/rpcclient/infrastructure.go @@ -809,6 +809,16 @@ func (c *Client) handleSendPostMessage(jReq *jsonRequest) { jReq.responseChan <- &Response{err: err} return } + // We still want to return an error if for any reason the respone + // remains empty. + if httpResponse == nil { + jReq.responseChan <- &Response{ + err: fmt.Errorf("invalid http POST response (nil), "+ + "method: %s, id: %d, last error=%v", + jReq.method, jReq.id, lastErr), + } + return + } // Read the raw bytes and close the response. respBytes, err := ioutil.ReadAll(httpResponse.Body)