From fb5ce3b87ae1726d85c7a672fa2e73df5c019918 Mon Sep 17 00:00:00 2001 From: jiuker <2818723467@qq.com> Date: Wed, 31 May 2023 01:07:26 +0800 Subject: [PATCH] record err time when remote node is offline (#17262) --- internal/rest/client.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/internal/rest/client.go b/internal/rest/client.go index e7e6485a1..1fba815f0 100644 --- a/internal/rest/client.go +++ b/internal/rest/client.go @@ -99,6 +99,7 @@ type Client struct { sync.RWMutex // mutex for lastErr lastErr error + lastErrTime time.Time } type restError string @@ -339,7 +340,7 @@ func (c *Client) LastConn() time.Time { func (c *Client) LastError() error { c.RLock() defer c.RUnlock() - return c.lastErr + return fmt.Errorf("[%s] %w", c.lastErrTime.Format(time.RFC3339), c.lastErr) } // computes the exponential backoff duration according to @@ -370,6 +371,7 @@ func exponentialBackoffWait(r *rand.Rand, unit, cap time.Duration) func(uint) ti func (c *Client) MarkOffline(err error) bool { c.Lock() c.lastErr = err + c.lastErrTime = time.Now() c.Unlock() // Start goroutine that will attempt to reconnect. // If server is already trying to reconnect this will have no effect.