Bug #1032
openLcdproc doesn't close TCP connections properly -> Too many open files -> VDR crashes
100%
Description
I'm running VDR 1.7.28 and the latest 0.0.10-jw9 version of lcdproc plugin. I have client HTPC in my living room with LCD display. A couple days ago VDR crashed and I found syslog was full of "ERROR (svdrp.c,127): Too many open files" messages:
Jun 22 10:17:09 vdr vdr: could not establish connection to LCDd at 192.168.0.9:13666.
Jun 22 10:19:12 vdr vdr: could not establish connection to LCDd at 192.168.0.9:13666.
Jun 22 10:20:10 vdr vdr: [1866] channel 2 (Yle TV2) event Pe 22.06.2012 10:20-10:30 'Yle Uutiset Keski-Suomi' status 4
Jun 22 10:21:15 vdr vdr: could not establish connection to LCDd at 192.168.0.9:13666.
Jun 22 10:22:02 vdr vdr: [1690] connect from 127.0.0.1, port 54884 - accepted
Jun 22 10:22:02 vdr vdr: [1690] closing SVDRP connection
Jun 22 10:23:15 vdr vdr: [1690] ERROR (svdrp.c,127): Too many open files
Jun 22 10:23:18 vdr vdr: last message repeated 2 times
Jun 22 10:23:18 vdr vdr: could not establish connection to LCDd at 192.168.0.9:13666.
Jun 22 10:23:18 vdr vdr: [1690] ERROR (svdrp.c,127): Too many open files
Jun 22 10:24:19 vdr vdr: last message repeated 46 times
Jun 22 10:25:18 vdr vdr: last message repeated 48 times
Jun 22 10:25:18 vdr vdr: [1866] ERROR: can't open filter handle on '/dev/dvb/adapter0/demux0'
Jun 22 10:25:19 vdr vdr: [1690] ERROR (svdrp.c,127): Too many open files
Jun 22 10:25:21 vdr vdr: last message repeated 2 times
I checked lsof -p $(pidof vdr) command and found lots of (maybe hundreds or one thousand) open sock connections (=open files):vdr 9543 vdr 27u sock 0,6 0t0 282216678 can't identify protocol
I look at code and noticed lcdproc doesn't close TCP socket properly, when TCP connection fails. So I changed code a little bit:diff --git a/sockets.c b/sockets.c
@ -70,6 +70,7
index 2df4fc7..71c54e6 100644
--- a/sockets.c
+++ b/sockets.c@ sock_connect (char *host, unsigned short int port)
if (err < 0) {
perror ("sock_connect: connect failed");
shutdown (sock, 2);
+ close (sock);
return 0; // Normal exit if server doesn't exist...
}
diff --git a/lcd.c b/lcd.c
@ -144,8 +144,14
index 15c9340..b2142ad 100644
--- a/lcd.c
+++ b/lcd.c@ void cLcd::Close() {
closing = true;
sock_send_string(sock,"screen_del VDR\n");
sock_recv(sock, istring, 1024);
usleep(1000000);
sock_close(sock);
+ if (sock!=0)
+ close(sock);
usleep(500000);
}else{
fprintf(stderr,"Not Connected !!! \n");
After these changes socket (open files) count doesn't increase anymore when my client HTPC is powered off.