From 4ca8320e18c37ec97376957982906a6756695c13 Mon Sep 17 00:00:00 2001 From: fiatjaf Date: Wed, 29 Jan 2025 22:12:42 -0300 Subject: [PATCH] actually this is the real fix. --- pool.go | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/pool.go b/pool.go index 8628853..1a59b87 100644 --- a/pool.go +++ b/pool.go @@ -263,13 +263,11 @@ func (pool *SimplePool) subMany( seenAlready := xsync.NewMapOf[string, Timestamp]() ticker := time.NewTicker(seenAlreadyDropTick) - eosed := false eoseWg := sync.WaitGroup{} eoseWg.Add(len(urls)) if eoseChan != nil { go func() { eoseWg.Wait() - eosed = true close(eoseChan) }() } @@ -285,12 +283,18 @@ func (pool *SimplePool) subMany( continue } + eosed := false + firstConnection := true + go func(nm string) { defer func() { pending.Dec() if pending.Value() == 0 { close(events) } + if !eosed { + eoseWg.Done() + } cancel() }() @@ -319,8 +323,15 @@ func (pool *SimplePool) subMany( relay, err := pool.EnsureRelay(nm) if err != nil { + // if we never connected to this just fail + if firstConnection { + return + } + + // otherwise (if we were connected and got disconnected) keep trying to reconnect goto reconnect } + firstConnection = false hasAuthed = false subscribe: @@ -340,6 +351,7 @@ func (pool *SimplePool) subMany( // guard here otherwise a resubscription will trigger a duplicate call to eoseWg.Done() if !eosed { + eosed = true eoseWg.Done() } }() @@ -396,8 +408,6 @@ func (pool *SimplePool) subMany( log.Printf("CLOSED from %s: '%s'\n", nm, reason) } - eoseWg.Done() - return case <-ctx.Done(): return