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
|
// queue all write operations here so we don't do mutex spaghetti
|
||||||
go func() {
|
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
|
pingAttempt := 0
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-r.connectionContext.Done():
|
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
|
return
|
||||||
|
|
||||||
case <-ticker.C:
|
case <-ticker.C:
|
||||||
@@ -192,6 +195,7 @@ func (r *Relay) ConnectWithTLS(ctx context.Context, tlsConfig *tls.Config) error
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
debugLogf("{%s} failed to close relay: %v", r.URL, err)
|
debugLogf("{%s} failed to close relay: %v", r.URL, err)
|
||||||
}
|
}
|
||||||
|
return
|
||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user