PassengerHelperAgent not releasing error file handles
Question 1: What is the problem? The PassengerHelperAgent creates a passenger-error file whenever it is not able to spawn a process. However it does not seem to be closing these files properly as the file handles remain open. On my machine, the file handles have been open for ~ 4 days now:
-rw------- 1 root root 331441 Nov 12 19:34 /tmp/passenger-error-o5rllv.html
-rw------- 1 root root 331472 Nov 12 19:19 /tmp/passenger-error-DYgzfO.html
-rw------- 1 root root 331441 Nov 12 19:10 /tmp/passenger-error-qVGpus.html
-rw------- 1 root root 331502 Nov 12 18:53 /tmp/passenger-error-0o1uxn.html
-rw------- 1 root root 331440 Nov 12 18:39 /tmp/passenger-error-2RwIbW.html
-rw------- 1 root root 331391 Nov 12 18:39 /tmp/passenger-error-6B6sIT.html
-rw------- 1 root root 331306 Nov 12 18:38 /tmp/passenger-error-PqTAnU.html
-rw------- 1 root root 331440 Nov 12 18:38 /tmp/passenger-error-MJIgFe.html
[ec2-user@ip-10-149-131-125 nginx]$ date
Wed Nov 16 10:15:12 UTC 2016
Over time, these file handles cause the process to exceed its open file limit and fail completely, and nginx logs are filled with messages like:
Backtrace:
in 'long long unsigned int Passenger::ApplicationPool2::Pool::realCollectAnalytics()' (Pool.h:867)
in 'static void Passenger::ApplicationPool2::Pool::collectAnalytics(Passenger::ApplicationPool2::PoolPtr)' (Pool.h:754)
[ 2016-11-16 10:05:58.0886 5664/7f17e204d700 Pool2/Pool.h:760 ]: ERROR: Cannot create a pipe: Too many open files (errno=24)
Backtrace:
in 'long long unsigned int Passenger::ApplicationPool2::Pool::realCollectAnalytics()' (Pool.h:867)
in 'static void Passenger::ApplicationPool2::Pool::collectAnalytics(Passenger::ApplicationPool2::PoolPtr)' (Pool.h:754)
These errors are so frequent that the error.log eventually fills up my disk itself.
While I can increase the open files limit to postpone this problem, I would prefer that these file handles are closed by the process , so I don't run into this problem in the first place.
-
What is the expected behavior? PassengerHelperAgent should close file handles for the passenger-error files
-
What is the actual behavior? The file handles are not released, causing the process to eventually exceed its limit.
-
How can we reproduce it? Not sure. Maybe it happens with any Rails application if passenger fails to spawn the process.
Question 2: Passenger version and integration mode:
- open source 4.0.53/nginx
Question 3: OS or Linux distro, platform (including version):
- Amazon Linux AMI release 2015.03 (Centos 5)
- Linux ip-10-149-131-125 4.4.19-29.55.amzn1.x86_64 #1 SMP Mon Aug 29 23:29:40 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
Question 4: Passenger installation method: [ ] RubyGems + Gemfile
Question 5: Your app's programming language (including any version managers) and framework (including versions):
- Ruby 2.1.6, RVM, Rails 3.2.0
Question 6: Are you using a PaaS and/or containerization? If so which one?
- No
Question 7: Anything else about your setup that we should know?
We strive for quality and appreciate you taking the time to submit a report! Please note that if you want guaranteed response times and priority issue support we encourage you to join our enterprise customer base. They also provide us with the means to continue our high level of open source support!
Looking at the passenger-4.0.53 code, looks like there's a bug in it where the FdGuard is initialized before opening the fd, so the correct fd doesn't get closed at all.
int fd = -1;
FdGuard guard(fd, true);
string errorPage;
I see this has been fixed in the latest version, so closing the issue.
For reference, here's the fix for the issue: https://github.com/phusion/passenger/issues/1324