Merge pull request #193 from mattn/fix/nostrfs-publish-relay-leak

nostrfs: reuse pooled relay connections when publishing notes
This commit is contained in:
mattn
2026-08-18 04:55:36 +00:00
committed by GitHub
+11 -6
View File
@@ -996,13 +996,18 @@ func (r *NostrRoot) publishNote(path string) {
}
for _, url := range relays {
connectCtx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
relay, err := nostr.RelayConnect(connectCtx, url, r.sys.Pool.RelayOptions)
cancel()
if err != nil {
continue
nm := nostr.NormalizeURL(url)
relay, ok := r.sys.Pool.Relays.Load(nm)
if !ok || relay == nil || !relay.IsConnected() {
connectCtx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
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)
}