From 4b8fa29963edcfeccb2a4f45174a92424aaa1f55 Mon Sep 17 00:00:00 2001 From: andig Date: Mon, 26 Feb 2024 11:17:57 +0100 Subject: [PATCH] RCT: fix retrying recoverable errors (#12476) --- meter/rct.go | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/meter/rct.go b/meter/rct.go index e9f947f5d..e929f77c7 100644 --- a/meter/rct.go +++ b/meter/rct.go @@ -83,7 +83,7 @@ func NewRCT(uri, usage string, cache time.Duration, capacity func() float64) (ap bo := backoff.NewExponentialBackOff() bo.InitialInterval = 10 * time.Millisecond - bo.MaxInterval = time.Second + bo.MaxElapsedTime = time.Second m := &RCT{ usage: strings.ToLower(usage), @@ -170,17 +170,15 @@ func (m *RCT) batterySoc() (float64, error) { // queryFloat adds retry logic of recoverable errors to QueryFloat32 func (m *RCT) queryFloat(id rct.Identifier) (float64, error) { - started := time.Now() m.bo.Reset() - for { - next := m.bo.NextBackOff() - + res, err := backoff.RetryWithData(func() (float32, error) { res, err := m.conn.QueryFloat32(id) - if err == nil || !errors.Is(err, &rct.RecoverableError{}) || time.Since(started)+next > m.bo.MaxElapsedTime { - return float64(res), err + if !errors.Is(err, rct.RecoverableError{}) { + err = backoff.Permanent(err) } + return res, err + }, m.bo) - time.Sleep(next) - } + return float64(res), err }