fix: torrent stats panic (#737)

This commit is contained in:
Levi authored and GitHub committed 2024-09-20 12:28:24 +08:00
1 parent 5c9bcd3731
commit d3750464aa
4 files changed
+17 -6

No files matched your search

+12 -1
View File
@@ -295,7 +295,7 @@ func (f *Fetcher) doUpload(fromUpload bool) {
continue
}
stats := f.torrent.Stats()
stats := f.torrentStats()
f.data.SeedBytes = lastData.SeedBytes + stats.BytesWrittenData.Int64()
// Check is download complete, if not don't check and stop seeding
@@ -332,6 +332,17 @@ func (f *Fetcher) doUpload(fromUpload bool) {
}
}
// Get torrent stats maybe panic, see https://github.com/anacrolix/torrent/issues/972
func (f *Fetcher) torrentStats() torrent.TorrentStats {
defer func() {
if r := recover(); r != nil {
// ignore panic
}
}()
return f.torrent.Stats()
}
func (f *Fetcher) UploadedBytes() int64 {
return f.data.SeedBytes
}