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()
|
defer r.closeMutex.Unlock()
|
||||||
|
|
||||||
if r.connectionContextCancel == nil {
|
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")
|
return fmt.Errorf("relay not connected")
|
||||||
}
|
}
|
||||||
|
|
||||||
r.connectionContextCancel()
|
err := r.Connection.Close()
|
||||||
r.connectionContextCancel = nil
|
r.Connection = nil
|
||||||
return r.Connection.Close()
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user