nostrfs: reuse pooled relay connections when publishing notes instead of leaking a new connection on every publish.

This commit is contained in:
Yasuhiro Matsumoto
2026-08-18 13:19:06 +09:00
parent 510c0039cc
commit 9a515ce4d1
+11 -6
View File
@@ -996,13 +996,18 @@ func (r *NostrRoot) publishNote(path string) {
} }
for _, url := range relays { for _, url := range relays {
connectCtx, cancel := context.WithTimeout(context.Background(), 2*time.Second) nm := nostr.NormalizeURL(url)
relay, err := nostr.RelayConnect(connectCtx, url, r.sys.Pool.RelayOptions) relay, ok := r.sys.Pool.Relays.Load(nm)
cancel() if !ok || relay == nil || !relay.IsConnected() {
if err != nil { connectCtx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
continue var err error
relay, err = nostr.RelayConnect(connectCtx, url, r.sys.Pool.RelayOptions)
cancel()
if err != nil {
continue
}
r.sys.Pool.Relays.Store(nm, relay)
} }
r.sys.Pool.Relays.Store(nostr.NormalizeURL(url), relay)
relay.Publish(ctx, *evt) relay.Publish(ctx, *evt)
} }