nip46: another client fix in the magic guarding of successfulness.

This commit is contained in:
fiatjaf
2026-05-21 17:32:32 -03:00
parent bb562d76a7
commit 13813b502a
+9 -6
View File
@@ -6,6 +6,7 @@ import (
"math/rand" "math/rand"
"net/url" "net/url"
"strconv" "strconv"
"sync"
"sync/atomic" "sync/atomic"
"time" "time"
"unsafe" "unsafe"
@@ -309,19 +310,21 @@ func (bunker *BunkerClient) RPC(ctx context.Context, method string, params []str
bunker.listeners.Store(id, dispatcher) bunker.listeners.Store(id, dispatcher)
defer bunker.listeners.Delete(id) defer bunker.listeners.Delete(id)
relayConnectionWorked := make(chan struct{}) relayConnectionWorked := make(chan struct{})
relayConnectionWorkedO := sync.OnceFunc(func() {
close(relayConnectionWorked)
})
bunkerConnectionWorked := make(chan struct{}) bunkerConnectionWorked := make(chan struct{})
bunkerConnectionWorkedO := sync.OnceFunc(func() {
close(bunkerConnectionWorked)
})
for _, url := range bunker.Relays { for _, url := range bunker.Relays {
go func(url string) { go func(url string) {
relay, err := bunker.pool.EnsureRelay(url) relay, err := bunker.pool.EnsureRelay(url)
if err == nil { if err == nil {
relayConnectionWorked <- struct{}{} relayConnectionWorkedO()
if err := relay.Publish(ctx, evt); err == nil { if err := relay.Publish(ctx, evt); err == nil {
select { bunkerConnectionWorkedO()
case bunkerConnectionWorked <- struct{}{}:
default:
}
} }
} }
}(url) }(url)