Skip to content

Commit fda71da

Browse files
authored
fix: Copy replicas to prevent race (coder#4596)
This was seen in https://github.com/coder/coder/actions/runs/3267638198/jobs/5373066836
1 parent 618c6dc commit fda71da

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

enterprise/replicasync/replicasync.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,14 @@ func (m *Manager) Self() database.Replica {
315315
func (m *Manager) All() []database.Replica {
316316
m.mutex.Lock()
317317
defer m.mutex.Unlock()
318-
return append(m.peers[:], m.self)
318+
replicas := make([]database.Replica, 0, len(m.peers))
319+
for _, replica := range append(m.peers, m.self) {
320+
// When we assign the non-pointer to a
321+
// variable it loses the reference.
322+
replica := replica
323+
replicas = append(replicas, replica)
324+
}
325+
return replicas
319326
}
320327

321328
// Regional returns all replicas in the same region excluding itself.

0 commit comments

Comments
 (0)