mirror of
https://github.com/coder/coder.git
synced 2025-07-23 21:32:07 +00:00
fix: Copy replicas to prevent race (#4596)
This was seen in https://github.com/coder/coder/actions/runs/3267638198/jobs/5373066836
This commit is contained in:
@ -315,7 +315,14 @@ func (m *Manager) Self() database.Replica {
|
||||
func (m *Manager) All() []database.Replica {
|
||||
m.mutex.Lock()
|
||||
defer m.mutex.Unlock()
|
||||
return append(m.peers[:], m.self)
|
||||
replicas := make([]database.Replica, 0, len(m.peers))
|
||||
for _, replica := range append(m.peers, m.self) {
|
||||
// When we assign the non-pointer to a
|
||||
// variable it loses the reference.
|
||||
replica := replica
|
||||
replicas = append(replicas, replica)
|
||||
}
|
||||
return replicas
|
||||
}
|
||||
|
||||
// Regional returns all replicas in the same region excluding itself.
|
||||
|
Reference in New Issue
Block a user