From 204feff171da03d7f7ccb735baffcc2b33aead29 Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Thu, 31 Jul 2025 11:49:14 +1000 Subject: [PATCH] Drop torrents on Client.Close not just close them --- client.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/client.go b/client.go index a0874f3c..3065e5d1 100644 --- a/client.go +++ b/client.go @@ -86,7 +86,8 @@ type Client struct { // All Torrents once. torrents map[*Torrent]struct{} // All Torrents by their short infohashes (v1 if valid, and truncated v2 if valid). Unless the - // info has been obtained, there's no knowing if an infohash belongs to v1 or v2. + // info has been obtained, there's no knowing if an infohash belongs to v1 or v2. TODO: Make + // this a weak pointer. torrentsByShortHash map[InfoHash]*Torrent // Piece request orderings grouped by storage. Value is value type because all fields are @@ -507,11 +508,14 @@ func (cl *Client) Close() (errs []error) { var closeGroup sync.WaitGroup // For concurrent cleanup to complete before returning cl.lock() for t := range cl.torrents { - err := t.close(&closeGroup) + // Can we not modify cl.torrents as we delete from it? + err := cl.dropTorrent(t, &closeGroup) if err != nil { errs = append(errs, err) } } + panicif.NotZero(len(cl.torrents)) + panicif.NotZero(len(cl.torrentsByShortHash)) cl.clearPortMappings() for i := range cl.onClose { cl.onClose[len(cl.onClose)-1-i]() -- 2.51.0