diff --git a/rpcclient/infrastructure.go b/rpcclient/infrastructure.go index 22430a2e1c8..b24e170225b 100644 --- a/rpcclient/infrastructure.go +++ b/rpcclient/infrastructure.go @@ -776,8 +776,10 @@ func (c *Client) handleSendPostMessage(jReq *jsonRequest) { tries := 10 for i := 0; i < tries; i++ { + var httpReq *http.Request + bodyReader := bytes.NewReader(jReq.marshalledJSON) - httpReq, err := http.NewRequest("POST", url, bodyReader) + httpReq, err = http.NewRequest("POST", url, bodyReader) if err != nil { jReq.responseChan <- &Response{result: nil, err: err} return @@ -815,6 +817,14 @@ func (c *Client) handleSendPostMessage(jReq *jsonRequest) { 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 response"), + } + } + // Read the raw bytes and close the response. respBytes, err := ioutil.ReadAll(httpResponse.Body) httpResponse.Body.Close()