mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-09-01 18:28:57 +02:00
relay: prevent panic on double-closing.
probably fixes https://github.com/nbd-wtf/go-nostr/issues/130
This commit is contained in:
16
relay.go
16
relay.go
@@ -487,10 +487,20 @@ func (r *Relay) Close() error {
|
||||
defer r.closeMutex.Unlock()
|
||||
|
||||
if r.connectionContextCancel == nil {
|
||||
return fmt.Errorf("relay already closed")
|
||||
}
|
||||
r.connectionContextCancel()
|
||||
r.connectionContextCancel = nil
|
||||
|
||||
if r.Connection == nil {
|
||||
return fmt.Errorf("relay not connected")
|
||||
}
|
||||
|
||||
r.connectionContextCancel()
|
||||
r.connectionContextCancel = nil
|
||||
return r.Connection.Close()
|
||||
err := r.Connection.Close()
|
||||
r.Connection = nil
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user