Bug #881

Runaway file-descriptors (patch included)

Added by Peter Nevermind over 1 year ago. Updated 10 months ago.

Status:FixedStart date:02/16/2012
Priority:NormalDue date:
Assignee:-% Done:

0%

Category:-
Target version:-
Found in version:fdf89b2768f131f16e3539757cb1cdd2e7ae5199 Affected Versions:

Description

Using the rather unstable XBMC-plugin as a frontend for tvheadend causes errors in tvheadend where file-descriptors are not closed when the client crashes while watching a recorded show. The error appears to be in src/webui/webui.c when a recording is served over HTTP and the client hangs up before the transfer is completed.

This ultimately leads to the user running out of descriptors (i think the standard limit is something like 1024) and errors start occurring in the logs:

Feb 15 16:55:34 atomic2 tvheadend[1439]: settings: Unable to create "/home/hts/.hts/tvheadend/dvbmuxes/_dev_dvb_adapter1_DiBcom_7000PC/_dev_dvb_adapter1_DiBcom_7000PC746000000.tmp" - Too many open files
Feb 15 16:56:27 atomic2 tvheadend[1439]: htsp: 192.168.45.218: Unable to generate challenge
Feb 15 17:04:31 atomic2 tvheadend[1439]: settings: Unable to create "/home/hts/.hts/tvheadend/dvbmuxes/_dev_dvb_adapter3_DiBcom_3000MC_P/_dev_dvb_adapter3_DiBcom_3000MC_P642000000.tmp" - Too many open files
Feb 15 17:04:31 atomic2 tvheadend[1439]: settings: Unable to create "/home/hts/.hts/tvheadend/dvbmuxes/_dev_dvb_adapter4_DiBcom_3000MC_P/_dev_dvb_adapter4_DiBcom_3000MC_P746000000.tmp" - Too many open files

The problem is easy to reproduce, just do a series of requests for a recording and watch the number of open files go up:

# lsof -p 24860 | wc -l
170
# wget http://192.168.45.67:9981/dvrfile/3584
(CTRL-C this before completed) 
# lsof -p 24860 | wc -l
171
# wget http://192.168.45.67:9981/dvrfile/3584
(CTRL-C this before completed) 
# lsof -p 24860 | wc -l
172

The fix for this is simple (diff against fdf89b2768f131f16e3539757cb1cdd2e7ae5199)

diff --git a/src/webui/webui.c b/src/webui/webui.c
index 2d81261..64a1cd6 100644
--- a/src/webui/webui.c
+++ b/src/webui/webui.c
@@ -609,8 +609,10 @@ page_dvrfile(http_connection_t *hc, const char *remain, void *opaque)
     while(content_len > 0) {
       chunk = MIN(1024 * 1024 * 1024, content_len);
       r = sendfile(hc->hc_fd, fd, NULL, chunk);
-      if(r == -1)
+      if(r == -1) {
+       close(fd);
        return -1;
+      }
       content_len -= r;
     }
   }

lsof.txt Magnifier (80.9 KB) Jonas Pedersen, 02/25/2012 09:04 am

History

#1 Updated by Jonas Pedersen about 1 year ago

I can confirm there is an issue with file descriptors not being closed. Please see attached output from lsof.

I will see if I can try above patch in the weekend and verify if that solves the issue.

#2 Updated by Jonas Pedersen about 1 year ago

Just did a simple test of the patch and can confirm it is working.

#3 Updated by Nathan McAullay 11 months ago

Hi there, I just noticed this error in my logs, wondering if it the patch will be included in a release? Cheers Nathan

#4 Updated by Adam Sutton 10 months ago

  • Status changed from New to Fixed

Patch appears to have been applied.

Also available in: Atom PDF