From 92162295af5a9f3e12a1303ffe6cc513d3a6e5ae Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Wed, 15 Apr 2020 13:07:17 +1000 Subject: [PATCH] Clone the AnnounceList out of Torrent.Metainfo Should fix a race with Torrent.AddTrackers --- metainfo/announcelist.go | 7 +++++++ torrent.go | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/metainfo/announcelist.go b/metainfo/announcelist.go index 3a5c09d4..b371f70d 100644 --- a/metainfo/announcelist.go +++ b/metainfo/announcelist.go @@ -2,6 +2,13 @@ package metainfo type AnnounceList [][]string +func (al AnnounceList) Clone() (ret AnnounceList) { + for _, tier := range al { + ret = append(ret, append([]string(nil), tier...)) + } + return +} + // Whether the AnnounceList should be preferred over a single URL announce. func (al AnnounceList) OverridesAnnounce(announce string) bool { for _, tier := range al { diff --git a/torrent.go b/torrent.go index db0126bf..d29c9a92 100644 --- a/torrent.go +++ b/torrent.go @@ -633,7 +633,7 @@ func (t *Torrent) newMetaInfo() metainfo.MetaInfo { CreationDate: time.Now().Unix(), Comment: "dynamic metainfo from client", CreatedBy: "go.torrent", - AnnounceList: t.metainfo.UpvertedAnnounceList(), + AnnounceList: t.metainfo.UpvertedAnnounceList().Clone(), InfoBytes: func() []byte { if t.haveInfo() { return t.metadataBytes -- 2.48.1