fix SubMany() global eosed tracking and SubManyNotifyEOSE() proper notification.

This commit is contained in:
fiatjaf 2025-01-29 21:36:08 -03:00
parent 78a9411d8a
commit 181234d774

View File

@ -263,12 +263,13 @@ func (pool *SimplePool) subMany(
seenAlready := xsync.NewMapOf[string, Timestamp]()
ticker := time.NewTicker(seenAlreadyDropTick)
eose := false
eosed := false
eoseWg := sync.WaitGroup{}
eoseWg.Add(len(urls))
if eoseChan != nil {
go func() {
eoseWg.Wait()
eosed = true
close(eoseChan)
}()
}
@ -338,8 +339,7 @@ func (pool *SimplePool) subMany(
<-sub.EndOfStoredEvents
// guard here otherwise a resubscription will trigger a duplicate call to eoseWg.Done()
if !eose {
eose = true
if !eosed {
eoseWg.Done()
}
}()
@ -374,7 +374,7 @@ func (pool *SimplePool) subMany(
return
}
case <-ticker.C:
if eose {
if eosed {
old := Timestamp(time.Now().Add(-seenAlreadyDropTick).Unix())
for id, value := range seenAlready.Range {
if value < old {