mirror of
https://github.com/btcsuite/btcd.git
synced 2025-03-10 17:26:07 +01:00
rpclient: fix masked error causing crash after max retries
This commit fixes the error that is masked inside the for loop's scope. Previously after max retries the error didn't leave the for scope and therefore httpResponse remained nil which in turn resulted in a crash.
This commit is contained in:
parent
ebed1927bf
commit
966511246d
1 changed files with 12 additions and 1 deletions
|
@ -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,15 @@ 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 http POST response (nil), "+
|
||||
"method: %s, id: %d", jReq.method, jReq.id),
|
||||
}
|
||||
}
|
||||
|
||||
// Read the raw bytes and close the response.
|
||||
respBytes, err := ioutil.ReadAll(httpResponse.Body)
|
||||
httpResponse.Body.Close()
|
||||
|
|
Loading…
Add table
Reference in a new issue