Skip to content

Commit fda71da

Browse files
authored
fix: Copy replicas to prevent race (#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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy