Skip to content

Commit

Permalink
relay: prevent panic on double-closing.
Browse files Browse the repository at this point in the history
probably fixes #130
  • Loading branch information
fiatjaf committed Jun 19, 2024
1 parent d6d0268 commit 37ef70e
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -487,10 +487,20 @@ func (r *Relay) Close() error {
defer r.closeMutex.Unlock()

if r.connectionContextCancel == nil {
return fmt.Errorf("relay not connected")
return fmt.Errorf("relay already closed")
}

r.connectionContextCancel()
r.connectionContextCancel = nil
return r.Connection.Close()

if r.Connection == nil {
return fmt.Errorf("relay not connected")
}

err := r.Connection.Close()
r.Connection = nil
if err != nil {
return err
}

return nil
}

0 comments on commit 37ef70e

Please sign in to comment.