anacrolix / torrent

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

torrent.KnownSwarm: keep client lock when iterating over connections #893

Closed veshij closed 5 months ago

veshij commented 5 months ago

We started seeing some rate of panics after we added periodic (*Torrent).KnownSwarm() call for debugging purposes. It looks like in a few other places operations with t.conns are processed while t.cl.rLock() is held, replicating the same behavior.

fatal error: concurrent map iteration and map write

goroutine 86949826 [running]:
github.com/anacrolix/torrent.(*Torrent).KnownSwarm(0xc00355a000)
        go/src/github.com/anacrolix/torrent/torrent.go:248 +0x17d
...
anacrolix commented 5 months ago

Good catch, thank you!