From: Matt Joiner Date: Thu, 31 Jul 2025 01:49:14 +0000 (+1000) Subject: Drop torrents on Client.Close not just close them X-Git-Tag: v1.59.0~2^2~83 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=204feff171da03d7f7ccb735baffcc2b33aead29;p=btrtrc.git Drop torrents on Client.Close not just close them --- 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]()