2

We're running a Rails app in Passenger 4.0.45 and nginx 1.6.0 (installed by Passenger installer) running on Ubuntu 14.04. Under heavy load Passenger restarts all of the application processes. After enabling passenger debug logs, I found "Cannot accept client: Too many open files (errno=24)" errors in the Passenger logs.

Nginx is configured with "worker_rlimit_nofile 200000". Using cat /proc/pid/limits I'm able to confirm that nginx has the correct limits. Our Rails app running in Passenger, however, is not getting a higher limit.

I've added to /etc/security/limits.conf to give all users a high limit, and I've added session required pam_limits.so to both /etc/pam.d/common-session and /etc/pam.d/common-session-noninteractive` and restarted.

I can run

su appuser --shell /bin/bash --command "ulimit -n"

and I get a high number.

I finally tried setting the limit within the Rails app by adding the following to an initializer:

Process.setrlimit(Process::RLIMIT_NOFILE, 65535)

The result is:

Operation not permitted - setrlimit (Errno::EPERM)
Robin Daugherty
  • 501
  • 5
  • 7
  • http://www.nginxtips.com/nginx-accept-failed-24-too-many-open-files/ – Florin Asăvoaie Jul 10 '14 at 21:55
  • Thanks @FlorinAsavoaie I just tried setting `sysctl.conf` as described there but the change seems to be redundant to the `limits.conf` change and nginx itself already has the correct limit. This is affecting the application processes, not nginx itself. – Robin Daugherty Jul 10 '14 at 22:27

1 Answers1

1

I got some help from Phusion to solve this problem, so here's the solution I came up with. When nginx starts on Ubuntu, the init script looks for /etc/default/nginx and runs commands found there before actually starting nginx.

So (in addition to the limits settings above) adding /etc/default/nginx with the following contents:

ulimit -Hn 200000
ulimit -Sn 200000

and then restarting nginx, fixed the issue. This applies to nginx and all of the passenger processes, including PassengerHelperAgent and the Rails processes.

womble
  • 96,255
  • 29
  • 175
  • 230
Robin Daugherty
  • 501
  • 5
  • 7