From 4e0b7ecc085f551e734bece94c59e3dda93e1665 Mon Sep 17 00:00:00 2001 From: Yasuhiro Matsumoto Date: Wed, 15 Jul 2026 03:49:01 +0900 Subject: [PATCH] helpers: guard the shared relays slice and render lines with a mutex in connectToAllRelays, parallel connections were racing and could drop relays. --- helpers.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/helpers.go b/helpers.go index 920ee81..ef17588 100644 --- a/helpers.go +++ b/helpers.go @@ -219,21 +219,28 @@ func connectToAllRelays( wg := sync.WaitGroup{} wg.Add(len(relayUrls)) + mu := sync.Mutex{} // guards lines and relays, written from the goroutines below for i, url := range relayUrls { lines[i] = make([][]byte, 1, 2) logthis := func(s string, args ...any) { + mu.Lock() lines[i] = append(lines[i], []byte(fmt.Sprintf(s, args...))) render() + mu.Unlock() } colorizepreamble := func(c func(string, ...any) string) { + mu.Lock() lines[i][0] = []byte(fmt.Sprintf("%s... ", c(url))) + mu.Unlock() } colorizepreamble(color.CyanString) go func() { relay := connectToSingleRelay(ctx, c, url, colorizepreamble, logthis) if relay != nil { + mu.Lock() relays = append(relays, relay) + mu.Unlock() } wg.Done() }()