Tighten up some potential leaks
Based on some observations of lingering goroutines in unit tests.
This commit is contained in:
parent
54339a30e3
commit
f69c51bea3
15
client.go
15
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()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue