diff --git a/client.go b/client.go index f5a52449..efa41e2c 100644 --- a/client.go +++ b/client.go @@ -551,14 +551,22 @@ func (cl *Client) stopped() bool { func (me *Client) Close() { me.mu.Lock() defer me.mu.Unlock() + select { + case <-me.quit: + return + default: + } close(me.quit) + if me.dHT != nil { + me.dHT.Close() + } for _, l := range me.listeners { l.Close() } - me.event.Broadcast() for _, t := range me.torrents { t.close() } + me.event.Broadcast() } var ipv6BlockRange = iplist.Range{Description: "non-IPv4 address"} @@ -586,6 +594,11 @@ func (cl *Client) waitAccept() { return } } + select { + case <-cl.quit: + return + default: + } cl.event.Wait() } }