anacrolix / torrent

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

once again some reader panics on read from storage with torrent@v1.49.0 #825

Closed tsynik closed 1 year ago

tsynik commented 1 year ago
2023/04/04 14:51:05 UTC0 Preload: 2258787cf663f2c93db20ee38bc2bfdc09833932 101.17MB/50.00MB Speed:0 Peers:[2]3/3
2023/04/04 14:51:06 UTC0 Preload: 2258787cf663f2c93db20ee38bc2bfdc09833932 101.17MB/50.00MB Speed:0 Peers:[2]3/3
2023/04/04 14:51:07 UTC0 Preload: 2258787cf663f2c93db20ee38bc2bfdc09833932 101.17MB/50.00MB Speed:0 Peers:[2]3/3
2023/04/04 14:51:08 UTC0 Close cache for: 2258787cf663f2c93db20ee38bc2bfdc09833932
2023/04/04 14:51:08 UTC0 Error preload: torrent closed
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x30 pc=0x1005bfdce]

goroutine 48530 [running]:
github.com/anacrolix/torrent/storage.Piece.ReadAt({{0x0?, 0x0?}, {0xc000f68100?, 0x0?}}, {0xc000fe6000, 0x8000, 0x8000}, 0x5758a3)
    /Users/nikk/go/pkg/mod/github.com/anacrolix/torrent@v1.49.0/storage/wrappers.go:84 +0x1ee
github.com/anacrolix/torrent.(*Torrent).readAt(0xc000374000, {0xc000fe6000?, 0xc000839e80?, 0x112ad758a3?}, 0x8000?)
    /Users/nikk/go/pkg/mod/github.com/anacrolix/torrent@v1.49.0/torrent.go:1370 +0x14d
github.com/anacrolix/torrent.(*reader).readOnceAt(0xc010828360, {0x100be1040, 0xc00003e030}, {0xc000fe6000, 0x8000, 0x8000}, 0x112ad758a3)
    /Users/nikk/go/pkg/mod/github.com/anacrolix/torrent@v1.49.0/reader.go:243 +0x230
github.com/anacrolix/torrent.(*reader).ReadContext(0xc010828360, {0x100be1040?, 0xc00003e030?}, {0xc000fe6000?, 0x8000, 0x8000?})
    /Users/nikk/go/pkg/mod/github.com/anacrolix/torrent@v1.49.0/reader.go:160 +0xaf
github.com/anacrolix/torrent.(*reader).Read(0xc010828360?, {0xc000fe6000?, 0x112b5758a3?, 0xc01b47f7a0?})
    /Users/nikk/go/pkg/mod/github.com/anacrolix/torrent@v1.49.0/reader.go:148 +0x38
server/torr.(*Torrent).Preload.func3()
    /Users/nikk/XCode/TorrServer/server/torr/preload.go:115 +0x150
created by server/torr.(*Torrent).Preload
    /Users/nikk/XCode/TorrServer/server/torr/preload.go:102 +0x645

here is TorrServer part: https://github.com/YouROK/TorrServer/blob/403384cea0b517e7950982d46f47af39eb4f2d7b/server/torr/preload.go#L102-L123

anacrolix commented 1 year ago

It looks like your PieceImpl is nil. It looks like there's probably a race between your storage implementation being closed, and continuing uses of it.

tsynik commented 1 year ago

It looks like your PieceImpl is nil. It looks like there's probably a race between your storage implementation being closed, and continuing uses of it.

Thanks for pointing me to right places, fixed on TorrServer side