fix: address nats callback review comments

This commit is contained in:
Jon Ayers
2026-05-29 19:12:02 +00:00
parent 344f501cce
commit 1111c3a7b9
3 changed files with 2 additions and 8 deletions
+1
View File
@@ -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
-2
View File
@@ -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
+1 -6
View File
@@ -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()
}