diff --git a/app/vmauth/auth_config.go b/app/vmauth/auth_config.go index 018dce6ba..63f177ef5 100644 --- a/app/vmauth/auth_config.go +++ b/app/vmauth/auth_config.go @@ -462,17 +462,12 @@ func getLeastLoadedBackendURL(bus []*backendURL, atomicCounter *atomic.Uint32) * // Slow path - select other backend urls. n := atomicCounter.Add(1) - 1 - buMin := bus[n%uint32(len(bus))] for i := uint32(0); i < uint32(len(bus)); i++ { idx := (n + i) % uint32(len(bus)) bu := bus[idx] if bu.isBroken() { continue } - if buMin.isBroken() { - // verify that buMin isn't set as broken - buMin = bu - } if bu.concurrentRequests.Load() == 0 { // Fast path - return the backend with zero concurrently executed requests. // Do not use CompareAndSwap() instead of Load(), since it is much slower on systems with many CPU cores. @@ -482,12 +477,13 @@ func getLeastLoadedBackendURL(bus []*backendURL, atomicCounter *atomic.Uint32) * } // Slow path - return the backend with the minimum number of concurrently executed requests. + buMin := bus[n%uint32(len(bus))] minRequests := buMin.concurrentRequests.Load() for _, bu := range bus { if bu.isBroken() { continue } - if n := bu.concurrentRequests.Load(); n < minRequests { + if n := bu.concurrentRequests.Load(); n < minRequests || buMin.isBroken() { buMin = bu minRequests = n }