// Stops the client. All connections to peers are closed and all activity will
// come to a halt.
-func (cl *Client) Close() {
+func (cl *Client) Close() (errs []error) {
cl.closed.Set()
var closeGroup sync.WaitGroup // For concurrent cleanup to complete before returning
cl.lock()
cl.event.Broadcast()
for _, t := range cl.torrents {
- t.close(&closeGroup)
+ err := t.close(&closeGroup)
+ if err != nil {
+ errs = append(errs, err)
+ }
}
cl.unlock()
closeGroup.Wait() // defer is LIFO. We want to Wait() after cl.unlock()
cl.onClose[len(cl.onClose)-1-i]()
}
cl.unlock()
+ return
}
func (cl *Client) ipBlockRange(ip net.IP) (r iplist.Range, blocked bool) {
func TestClientDefault(t *testing.T) {
cl, err := NewClient(TestingConfig(t))
require.NoError(t, err)
- cl.Close()
+ require.Empty(t, cl.Close())
}
func TestClientNilConfig(t *testing.T) {
os.Chdir(t.TempDir())
cl, err := NewClient(nil)
require.NoError(t, err)
- cl.Close()
+ require.Empty(t, cl.Close())
}
func TestAddDropTorrent(t *testing.T) {
return fmt.Errorf("creating client: %w", err)
}
var clientClose sync.Once //In certain situations, close was being called more than once.
- defer clientClose.Do(client.Close)
+ defer clientClose.Do(func() { client.Close() })
go exitSignalHandlers(&stop)
go func() {
<-stop.C()
- clientClose.Do(client.Close)
+ clientClose.Do(func() { client.Close() })
}()
// Write status on the root path on the default HTTP muxer. This will be bound to localhost