mirror of
https://github.com/fiatjaf/nak.git
synced 2026-09-13 22:25:06 +00:00
Merge pull request #193 from mattn/fix/nostrfs-publish-relay-leak
nostrfs: reuse pooled relay connections when publishing notes
This commit is contained in:
+11
-6
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user