anacrolix / torrent

Full-featured BitTorrent client package and utilities
Mozilla Public License 2.0
5.51k stars 622 forks source link

Panic when dropping a torrent #813

Closed JaskaranSM closed 1 year ago

JaskaranSM commented 1 year ago

Hi, the client panicked when it was dropping a torrent, My code drops the torrent from the client when the torrent gets completed (this is governed by the torrent's Complete flag). I do not have any idea on what does relative availability means in this context. Here's the traceback I got from my app logs:

seasonal-go  | panic: piece 0 has relative availability 2
seasonal-go  |
seasonal-go  | goroutine 25561611 [running]:
seasonal-go  | github.com/anacrolix/torrent.(*Torrent).close(0x401a325500, 0x400f46df70)
seasonal-go  |  /home/runner/go/pkg/mod/github.com/anacrolix/torrent@v1.47.1-0.20221102120345-c63f7e1bd720/torrent.go:895 +0x240
seasonal-go  | github.com/anacrolix/torrent.(*Client).dropTorrent(0x4000446d80, {0x24, 0x23, 0x4c, 0x6b, 0x1d, 0xaa, 0xc6, 0xcd, 0x16, ...}, ...)
seasonal-go  |  /home/runner/go/pkg/mod/github.com/anacrolix/torrent@v1.47.1-0.20221102120345-c63f7e1bd720/client.go:1366 +0x60
seasonal-go  | github.com/anacrolix/torrent.(*Torrent).Drop(0x401a325500)
seasonal-go  |  /home/runner/go/pkg/mod/github.com/anacrolix/torrent@v1.47.1-0.20221102120345-c63f7e1bd720/t.go:103 +0xe0
seasonal-go  | seasonal-go/engine.(*TorrentDownloadListener).OnDownloadComplete(0x401b501050)
seasonal-go  |  /home/runner/work/seasonal-go/seasonal-go/engine/download-manager.go:39 +0xf0
seasonal-go  | seasonal-go/engine.(*TorrentDownloadListener).ListenForEvents(0x401b501050)
seasonal-go  |  /home/runner/work/seasonal-go/seasonal-go/engine/download-manager.go:78 +0xd0
seasonal-go  | created by seasonal-go/engine.(*TorrentDownloadListener).StartListener
seasonal-go  |  /home/runner/work/seasonal-go/seasonal-go/engine/download-manager.go:87 +0x68
anacrolix commented 1 year ago

Thanks for the report. This panic should indicate inconsistency in the state used to request pieces from peers. Does it happen often?

JaskaranSM commented 1 year ago

No, its the first time i m seeing this error.

JaskaranSM commented 1 year ago

Got this again today.

anacrolix commented 1 year ago

Could you try with https://github.com/anacrolix/torrent/commit/e8971ea0f1bfb26e2e05eea6e98a547dfb231bb9? I'm pretty sure there's no data race issue here, so I'm suspecting an unexpected ordering of messages or events.

anacrolix commented 1 year ago

Per #820, do you want to try with 1.48.0 or 1.47.0 and cherry pick the fix https://github.com/anacrolix/torrent/commit/e8971ea0f1bfb26e2e05eea6e98a547dfb231bb9, unless we resolve the other issue first?

anacrolix commented 1 year ago

I suspect this is fixed, please ensure you are on v1.51.0 or newer if it comes up again.