anacrolix / torrent

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

win: udp too large datagram #764

Closed AskAlexSharov closed 1 year ago

AskAlexSharov commented 2 years ago
panic: read udp6 [::]:53397: wsarecvfrom: A message sent on a datagram socket was larger than the internal message buffer or some other network limit, or the buffer used to receive a datagram into was smaller than the datagram itself.

trace

goroutine 253 [running]:
github.com/anacrolix/torrent/tracker/udp.(*ConnClient).reader(0xc08406a140)
github.com/anacrolix/torrent@v1.44.0/tracker/udp/conn-client.go:42 +0x295
created by github.com/anacrolix/torrent/tracker/udp.NewConnClient
github.com/anacrolix/torrent@v1.44.0/tracker/udp/conn-client.go:102 +0x245
panic: read udp6 [::]:53394: wsarecvfrom: A message sent on a datagram socket was larger than the internal message buffer or some other network limit, or the buffer used to receive a datagram into was smaller than the datagram itself.

goroutine 275 [running]:
github.com/anacrolix/torrent/tracker/udp.(*ConnClient).reader(0xc083fa4000)
github.com/anacrolix/torrent@v1.44.0/tracker/udp/conn-client.go:42 +0x295
created by github.com/anacrolix/torrent/tracker/udp.NewConnClient
github.com/anacrolix/torrent@v1.44.0/tracker/udp/conn-client.go:102 +0x245
[15:38:04.32] erigon exited with error 2 (aborting)

also user noticed announce with many peers: https://github.com/ledgerwatch/erigon/issues/4674#issuecomment-1178356276

Our setup: 100 torrents, EstablishedConnsPerTorrent=10

Link to original issue: https://github.com/ledgerwatch/erigon/issues/4674

anacrolix commented 2 years ago

This looks related to https://github.com/anacrolix/torrent/issues/712, which comes out of an issue with Windows reporting UDP warnings as errors. I believe it's a longstanding issue and I think the Go core needs to address it.

The example announce response in https://github.com/ledgerwatch/erigon/issues/4674#issuecomment-1178356276 has 200 peers. It may be that that particular tracker is not using a smarter default for the NumWant field for UDP announces, which anacrolix/torrent is probably setting to -1, here: https://github.com/anacrolix/torrent/blob/75cc4e98d4ae847b990d5a4292ed0deafa2edb92/torrent.go#L1712-L1718. You could try setting that to a specific value instead of -1, such as 200 (which appeared to work in the comment), or 50 or 100.

anacrolix commented 1 year ago

Did this fix work for you @AskAlexSharov ? I could have sworn I added a check to automatically limit NumWant, maybe it's in a branch.

AskAlexSharov commented 1 year ago

Seems yes… thank you