From 38cf5bffaae890791e35336b0d844e2dbd974466 Mon Sep 17 00:00:00 2001 From: Kyle Carberry Date: Mon, 17 Oct 2022 19:13:52 +0000 Subject: [PATCH] fix: Copy replicas to prevent race This was seen in https://github.com/coder/coder/actions/runs/3267638198/jobs/5373066836 --- enterprise/replicasync/replicasync.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/enterprise/replicasync/replicasync.go b/enterprise/replicasync/replicasync.go index daac634efeb74..68344c91f7315 100644 --- a/enterprise/replicasync/replicasync.go +++ b/enterprise/replicasync/replicasync.go @@ -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. 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