fix: shuffle users in team balancer to prevent ordering bias on app restart

This commit is contained in:
Abhinav Raut
2025-03-06 20:34:51 +05:30
parent 277586f025
commit 9892f9dae7
+7
View File
@@ -5,6 +5,7 @@ import (
"context"
"errors"
"fmt"
"math/rand"
"strconv"
"sync"
"time"
@@ -145,6 +146,12 @@ func (e *Engine) populateTeamBalancer() error {
continue
}
// Shuffle users to prevent ordering bias, as every app restart will pick the same first user.
r := rand.New(rand.NewSource(time.Now().UnixNano()))
r.Shuffle(len(users), func(i, j int) {
users[i], users[j] = users[j], users[i]
})
for _, user := range users {
// Team does not have a balancer pool, create one.
if _, ok := e.roundRobinBalancer[team.ID]; !ok {