Skip to content

Commit

Permalink
rpcclient: save the last error when retrying
Browse files Browse the repository at this point in the history
  • Loading branch information
bhandras committed May 12, 2022
1 parent fff3453 commit 91757ae
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions rpcclient/infrastructure.go
Original file line number Diff line number Diff line change
Expand Up @@ -771,7 +771,7 @@ func (c *Client) handleSendPostMessage(jReq *jsonRequest,
url := protocol + "://" + c.config.Host

var (
err error
err, lastErr error
backoff time.Duration
httpResponse *http.Response
)
Expand Down Expand Up @@ -807,6 +807,12 @@ func (c *Client) handleSendPostMessage(jReq *jsonRequest,
break
}

// Save the last error for the case where we backoff further,
// retry and get an invalid response but no error. If this
// happens the saved last error will be used to enrich the error
// message that we pass back to the caller.
lastErr = err

// Backoff sleep otherwise.
backoff = requestRetryInterval * time.Duration(i+1)
if backoff > time.Minute {
Expand All @@ -832,7 +838,8 @@ func (c *Client) handleSendPostMessage(jReq *jsonRequest,
// remains empty.
if httpResponse == nil {
jReq.responseChan <- &Response{
err: fmt.Errorf("invalid response"),
err: fmt.Errorf("invalid response, last error=%v",
lastErr),
}
}

Expand Down

0 comments on commit 91757ae

Please sign in to comment.