Project

General

Profile

Actions

Bug #1032

open

Lcdproc doesn't close TCP connections properly -> Too many open files -> VDR crashes

Added by Anonymous over 12 years ago. Updated almost 10 years ago.

Status:
Resolved
Priority:
Normal
Assignee:
-
Target version:
Start date:
06/24/2012
Due date:
% Done:

100%

Estimated time:

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
index 2df4fc7..71c54e6 100644
--- a/sockets.c
+++ b/sockets.c
@ -70,6 +70,7 @ 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
index 15c9340..b2142ad 100644
--- a/lcd.c
+++ b/lcd.c
@ -144,8 +144,14 @ 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.

Actions #1

Updated by jowi24 over 12 years ago

  • Status changed from New to Assigned

Thanks for the patch! Would you please verify, that this slightly adopted version still fixes your issue?

This is also available as branch "fix_socket" in git.

diff --git a/sockets.c b/sockets.c
index 2df4fc7..a95d660 100644
--- a/sockets.c
+++ b/sockets.c
@@ -69,7 +69,7 @@ sock_connect (char *host, unsigned short int port)
        err = connect (sock, (struct sockaddr *) &servername, sizeof (servername));
        if (err < 0) {
                perror ("sock_connect: connect failed");
-               shutdown (sock, 2);
+               sock_close (sock);
                return 0;                                         // Normal exit if server doesn't exist...
        }

@@ -84,8 +84,7 @@ sock_close (int fd)
        int err;

        err = shutdown (fd, 2);
-       if (!err)
-               close (fd);
+       close (fd);

        return err;
 }
Actions #2

Updated by noeikujoo over 12 years ago

jowi24 wrote:

Thanks for the patch! Would you please verify, that this slightly adopted version still fixes your issue?

Yes, it seems to fix this issue. I have tested the new "fix_socket" branch version today and the problem no longer occurred.

Actions #3

Updated by jowi24 over 12 years ago

  • Status changed from Assigned to Resolved
  • Assignee set to jowi24
  • Target version set to 0.0.10-jw10
  • % Done changed from 0 to 100

Great. I'll merge it in lcdproc master. Thanks again!

If you like to be credited other than "noeikujoo" please contact me.

Actions #4

Updated by jowi24 almost 10 years ago

  • Assignee deleted (jowi24)
Actions

Also available in: Atom PDF