Possible FD leak in webtorrent stream 1.9.9
Some time ago i have added few remote cameras re-streamed via webtorrent, because I wanted this traffic to avoid VPN. For some time that worked well, but then I started noticing troubles on rx go2rtc instance, when some of that cameras not working.
With 5 this webtorrent streams not connected I ran out of FDs limit in a few hours (tried to go up from 4k to 256k limit nofile). What I see - lots of sockets left open.
Here is normal state (when left only local RTSP streams):
root@go2rtc:~# lsof -p 2936 | wc -l
160
And here about 5 minutes with webtorrent streams:
root@go2rtc:~# lsof -p 12096 | wc -l
401
root@go2rtc:~# lsof -p 12096 | wc -l
447
root@go2rtc:~# lsof -p 12096 | wc -l
548
root@go2rtc:~# lsof -p 12096 | wc -l
690
I see lots of open UDP sockets, example:
go2rtc 12096 go2rtc 12u IPv4 218029 0t0 TCP 192.168.25.200:34036->hiw-i400-cam20.lan:rtsp (ESTABLISHED)
go2rtc 12096 go2rtc 13u IPv6 216773 0t0 TCP 192.168.25.200:8555->frigate.lan:36225 (ESTABLISHED)
go2rtc 12096 go2rtc 14u IPv6 226599 0t0 TCP go2rtc.lan:1984->frigate.lan:37138 (ESTABLISHED)
go2rtc 12096 go2rtc 15u IPv4 216805 0t0 UDP *:mdns
go2rtc 12096 go2rtc 16u IPv4 219405 0t0 UDP *:59873
go2rtc 12096 go2rtc 17u IPv4 218095 0t0 UDP *:33639
go2rtc 12096 go2rtc 18u IPv4 218094 0t0 UDP *:50066
go2rtc 12096 go2rtc 19u IPv6 225671 0t0 TCP go2rtc.lan:1984->frigate.lan:37136 (ESTABLISHED)
go2rtc 12096 go2rtc 20u IPv4 218772 0t0 UDP *:mdns
go2rtc 12096 go2rtc 21u IPv4 219291 0t0 UDP *:mdns
go2rtc 12096 go2rtc 22u IPv4 216707 0t0 UDP *:mdns
go2rtc 12096 go2rtc 23u IPv4 219293 0t0 UDP *:42843
Many of which on a random port, but also a lot on mdns:
root@go2rtc:~# lsof -p 12096 | fgrep ':mdns' | wc -l
165
root@go2rtc:~# lsof -p 12096 | fgrep ':mdns' | wc -l
172
Total amount of UDP slowly grows:
root@go2rtc:~# lsof -p 12096 | fgrep 'UDP' | wc -l
1121
root@go2rtc:~# lsof -p 12096 | fgrep 'UDP' | wc -l
1133
root@go2rtc:~# lsof -p 12096 | fgrep 'UDP' | wc -l
1139
root@go2rtc:~# lsof -p 12096 | fgrep 'UDP' | wc -l
1174
TCP also have some slow grow, but here seems some of the sockets were closed:
root@go2rtc:~# lsof -p 12096 | fgrep 'TCP' | wc -l
287
root@go2rtc:~# lsof -p 12096 | fgrep 'TCP' | wc -l
293
root@go2rtc:~# lsof -p 12096 | fgrep 'TCP' | wc -l
293
root@go2rtc:~# lsof -p 12096 | fgrep 'TCP' | wc -l
297
root@go2rtc:~# lsof -p 12096 | fgrep 'TCP' | wc -l
299
root@go2rtc:~# lsof -p 12096 | fgrep 'TCP' | wc -l
307
root@go2rtc:~# lsof -p 12096 | fgrep 'TCP' | wc -l
305
root@go2rtc:~# lsof -p 12096 | fgrep 'TCP' | wc -l
301
root@go2rtc:~# lsof -p 12096 | fgrep 'TCP' | wc -l
303
root@go2rtc:~# lsof -p 12096 | fgrep 'TCP' | wc -l
303
Version: 1.9.9 built from source Go: 1.25.0 Arch: x86_64