Bug #3678
[epggrab] unix domain socket is not closed
0%
Description
Hi,
The accepted unix domain socket used for epggrab module is not closed after grabbing.
How to reproduce:
1. initially, there is only one listening socket
$ lsof -p $TVH_PID | grep xmltv.sock tvheadend 17734 hts 20u unix 0xffff88070f4a34c0 0t0 1488041359 /home/hts/.hts/tvheadend/epggrab/xmltv.sock
2. send epg to xmltv.sock 5 times
$ cat xmltv.xml | socat - UNIX-CONNECT:/home/hts/.hts/tvheadend/epggrab/xmltv.sock $ cat xmltv.xml | socat - UNIX-CONNECT:/home/hts/.hts/tvheadend/epggrab/xmltv.sock $ cat xmltv.xml | socat - UNIX-CONNECT:/home/hts/.hts/tvheadend/epggrab/xmltv.sock $ cat xmltv.xml | socat - UNIX-CONNECT:/home/hts/.hts/tvheadend/epggrab/xmltv.sock $ cat xmltv.xml | socat - UNIX-CONNECT:/home/hts/.hts/tvheadend/epggrab/xmltv.sock
3. now there's 6 sockets. 5 of them should have been closed
$ lsof -p $TVH_PID | grep xmltv.sock tvheadend 17734 hts 20u unix 0xffff88070f4a34c0 0t0 1488041359 /home/hts/.hts/tvheadend/epggrab/xmltv.sock tvheadend 17734 hts 24u unix 0xffff8804df7bd880 0t0 1488041362 /home/hts/.hts/tvheadend/epggrab/xmltv.sock tvheadend 17734 hts 25u unix 0xffff88021d2db0c0 0t0 1488075867 /home/hts/.hts/tvheadend/epggrab/xmltv.sock tvheadend 17734 hts 26u unix 0xffff8806d77c3840 0t0 1488076686 /home/hts/.hts/tvheadend/epggrab/xmltv.sock tvheadend 17734 hts 30u unix 0xffff8804ac153400 0t0 1488077181 /home/hts/.hts/tvheadend/epggrab/xmltv.sock tvheadend 17734 hts 31u unix 0xffff88044324e100 0t0 1488086366 /home/hts/.hts/tvheadend/epggrab/xmltv.sock
I have created simple patch to this bug. Please take a look.
https://github.com/axfree/tvheadend/commit/5fabbf8638cbb92a1ca323b7387bef719814c7c1
History
Updated by Adam Bowen over 8 years ago
I can confirm the issue. I was seeing 85 sockets opened every time I updated the EPG (which I do manually, per channel, using the XMLTV socket). I've rebuilt using the patched source and after a full EPG update I have 30 left open (which is the same number that are already open before the update - and seem to be created when the tvheadend process first starts up).
Nice find this. I've been having an issue with the tvheadend process hanging in the middle of an EPG update every 3 months or so, so I'm hoping that it was caused by the system running out of file handles, and that this will fix it.
~100 days * 85 sockets = 85,000, and file-max on my raspberry pi2 is 98,736, so it seems plausible. Time will tell.
Updated by Adam Bowen over 8 years ago
Oops. That's not right. That should only be 8,500 sockets. I ran a couple more tests and I actually seem to see the socket count (using the lsof above) increase by factors of 30. I'll need to go back and do another test when I have time.
Updated by Adam Bowen over 8 years ago
The factor of 30 thing is because I didn't limit the lsof command to the parent ID, so I was also getting results for each thread. I actually just have one open handle for the base process, so the fix is working as expected.
Updated by Jaroslav Kysela over 8 years ago
- Status changed from New to Fixed
Fixed in v4.1-1783-g25f2e54 .