mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-11-18 10:06:27 +01:00
chore: make relay cleanup more clear
This commit is contained in:
16
relay.go
16
relay.go
@@ -167,16 +167,19 @@ func (r *Relay) ConnectWithTLS(ctx context.Context, tlsConfig *tls.Config) error
|
||||
|
||||
// queue all write operations here so we don't do mutex spaghetti
|
||||
go func() {
|
||||
defer func() {
|
||||
ticker.Stop()
|
||||
r.Connection = nil
|
||||
|
||||
for _, sub := range r.Subscriptions.Range {
|
||||
sub.unsub(fmt.Errorf("relay connection closed: %w / %w", context.Cause(r.connectionContext), r.ConnectionError))
|
||||
}
|
||||
}()
|
||||
|
||||
pingAttempt := 0
|
||||
for {
|
||||
select {
|
||||
case <-r.connectionContext.Done():
|
||||
ticker.Stop()
|
||||
r.Connection = nil
|
||||
|
||||
for _, sub := range r.Subscriptions.Range {
|
||||
sub.unsub(fmt.Errorf("relay connection closed: %w / %w", context.Cause(r.connectionContext), r.ConnectionError))
|
||||
}
|
||||
return
|
||||
|
||||
case <-ticker.C:
|
||||
@@ -192,6 +195,7 @@ func (r *Relay) ConnectWithTLS(ctx context.Context, tlsConfig *tls.Config) error
|
||||
if err != nil {
|
||||
debugLogf("{%s} failed to close relay: %v", r.URL, err)
|
||||
}
|
||||
return
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user