Skip to content

Commit

Permalink
Reset rolling strategies state after sorting
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
billettc committed Dec 11, 2024
1 parent d7f9264 commit 6b458ae
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions rpc/clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}()
Expand Down

0 comments on commit 6b458ae

Please sign in to comment.