From 97313ac873eee4365fc1de253a538335defcfed7 Mon Sep 17 00:00:00 2001 From: Andras Banki-Horvath Date: Thu, 12 May 2022 22:09:38 +0200 Subject: [PATCH] rpcclient: save the last error when retrying --- rpcclient/infrastructure.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/rpcclient/infrastructure.go b/rpcclient/infrastructure.go index b7732bc6..f931b835 100644 --- a/rpcclient/infrastructure.go +++ b/rpcclient/infrastructure.go @@ -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 ) @@ -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 { @@ -833,7 +839,8 @@ func (c *Client) handleSendPostMessage(jReq *jsonRequest, if httpResponse == nil { jReq.responseChan <- &Response{ err: fmt.Errorf("invalid http POST response (nil), "+ - "method: %s, id: %d", jReq.method, jReq.id), + "method: %s, id: %d, last error=%v", + jReq.method, jReq.id, lastErr), } }