From 5fb676a6b73ff8d184559a1a1b0beabd503af0db Mon Sep 17 00:00:00 2001 From: Charles Billette Date: Wed, 27 Nov 2024 09:18:05 -0500 Subject: [PATCH] Reset rolling strategies state after sorting Ensure the rolling strategies reset internal state variables such as `usedClientCount`, `nextClientIndex`, and others after encountering sorting errors. This is to guarantee proper client selection behavior in subsequent retries. --- rpc/clients.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/rpc/clients.go b/rpc/clients.go index 36a0066..30023c9 100644 --- a/rpc/clients.go +++ b/rpc/clients.go @@ -36,6 +36,16 @@ func (c *Clients[C]) StartSorting(ctx context.Context, direction SortDirection, if err != nil { c.logger.Warn("sorting", zap.Error(err)) } + + switch s := c.rollingStrategy.(type) { + case *StickyRollingStrategy[C]: + s.fistCallToNewClient = true + s.usedClientCount = 0 + s.nextClientIndex = 0 + case *RollingStrategyAlwaysUseFirst[C]: + s.nextIndex = 0 + } + time.Sleep(every) } }()