anacrolix / torrent

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

Support notifying user of internal client errors #811

Open colinmarc opened 1 year ago

colinmarc commented 1 year ago

It's possible to get a torrent into an infinite error loop. For example, if you chown -R root /tmp/torrents and then try to run the default file storage over that directory, the torrent client will just spew errors forever like:

2023-02-11T15:45:07+0100 ERR [github.com/anacrolix/torrent.(*Peer).receiveChunk:1536]: *torrent.PeerConn 0xc001414000 [id="-qB4500-vtmhGE65sBwN", exts=0000000000180005, v="qBittorrent/4.5.0"]: writing received chunk 402: open /tmp/torrentd/downloads/dd8255ecdc7ca55fb0bbf81323d87062db1f6d1c/Big Buck Bunny.mp4: permission denied
2023-02-11T15:45:07+0100 CRT [torrent dd8255ecdc7ca55fb0bbf81323d87062db1f6d1c github.com/anacrolix/torrent.(*Torrent).onWriteChunkErr:2314]: "Big Buck Bunny": default chunk write error handler: disabling data download
2023-02-11T15:45:07+0100 NIL [torrent dd8255ecdc7ca55fb0bbf81323d87062db1f6d1c github.com/anacrolix/torrent.(*Torrent).pieceHasher:2198]: "Big Buck Bunny": piece dd8255ecdc7ca55fb0bbf81323d87062db1f6d1c/130 (f4578464fe213415b4d55c7d1527cf2519078d95) hash failure copy error: open /tmp/torrentd/downloads/dd8255ecdc7ca55fb0bbf81323d87062db1f6d1c/Big Buck Bunny.mp4: permission denied
2023-02-11T15:45:08+0100 ERR [github.com/anacrolix/torrent.(*Peer).receiveChunk:1536]: *torrent.PeerConn 0xc00139c000 [id="-qB4250-*P2a7~)8(cC)", exts=0000000000180005, v="qBittorrent/4.2.5"]: writing received chunk 307: open /tmp/torrentd/downloads/dd8255ecdc7ca55fb0bbf81323d87062db1f6d1c/Big Buck Bunny.mp4: permission denied
2023-02-11T15:45:08+0100 NIL [torrent dd8255ecdc7ca55fb0bbf81323d87062db1f6d1c github.com/anacrolix/torrent.(*Torrent).pieceHasher:2198]: "Big Buck Bunny": piece dd8255ecdc7ca55fb0bbf81323d87062db1f6d1c/131 (c16b55e2675f4693a82355bad030f234e130cd11) hash failure copy error: open /tmp/torrentd/downloads/dd8255ecdc7ca55fb0bbf81323d87062db1f6d1c/Big Buck Bunny.mp4: permission denied

Is there a way for a caller to detect that the torrent is in an errored state and cancel it, or at least report that to the user?

anacrolix commented 1 year ago

I haven't tested the case where hash checks fail. A unit test for this would be fantastic and easy to do. Let me know if you're interested, or I can create one.

There isn't really any errors exposed at the moment, this would be a good case to expose one. Let me know if you have thoughts on how that should look. The only existing precedent I think for something like this is https://pkg.go.dev/github.com/anacrolix/torrent#Torrent.SetOnWriteChunkError. I expect this could be generalized to serious errors like this case.