From 1111c3a7b9185024e38f41cff6988255a2786b61 Mon Sep 17 00:00:00 2001 From: Jon Ayers Date: Fri, 29 May 2026 19:12:02 +0000 Subject: [PATCH] fix: address nats callback review comments --- coderd/x/nats/cluster.go | 1 + enterprise/coderd/coderd.go | 2 -- enterprise/replicasync/replicasync.go | 7 +------ 3 files changed, 2 insertions(+), 8 deletions(-) diff --git a/coderd/x/nats/cluster.go b/coderd/x/nats/cluster.go index 5f609bd6d9..d54839c02a 100644 --- a/coderd/x/nats/cluster.go +++ b/coderd/x/nats/cluster.go @@ -143,6 +143,7 @@ func routesWithAuth(routes []*url.URL, token string) []*url.URL { return withAuth } +// sortedURLsEqual assumes sorted slices. func sortedURLsEqual(a, b []*url.URL) bool { if len(a) != len(b) { return false diff --git a/enterprise/coderd/coderd.go b/enterprise/coderd/coderd.go index 4c46cff150..9ecd11c068 100644 --- a/enterprise/coderd/coderd.go +++ b/enterprise/coderd/coderd.go @@ -107,8 +107,6 @@ func replicaNATSPeerAddresses(rm *replicasync.Manager) []string { if replica.RelayAddress == "" { continue } - // coderd/x/nats accepts relay-style URLs here and normalizes the host - // to the NATS route port. addresses = append(addresses, replica.RelayAddress) } return addresses diff --git a/enterprise/replicasync/replicasync.go b/enterprise/replicasync/replicasync.go index 8fe5688856..3a7afb3c6f 100644 --- a/enterprise/replicasync/replicasync.go +++ b/enterprise/replicasync/replicasync.go @@ -359,11 +359,7 @@ func (m *Manager) syncReplicas(ctx context.Context) error { } } m.self = replica - callbacks := make([]func(), 0, len(m.callbacks)) for _, callback := range m.callbacks { - callbacks = append(callbacks, callback) - } - for _, callback := range callbacks { go callback() } return nil @@ -448,16 +444,15 @@ func (m *Manager) regionID() int32 { // callback. Passing nil removes the named callback. func (m *Manager) SetCallback(name string, callback func()) { m.mutex.Lock() + defer m.mutex.Unlock() if callback == nil { delete(m.callbacks, name) - m.mutex.Unlock() return } if m.callbacks == nil { m.callbacks = make(map[string]func()) } m.callbacks[name] = callback - m.mutex.Unlock() // Instantly call the callback to inform replicas! go callback() }