Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix file descriptor leak on /dev/urandom each time nginx reloads #6

Merged
merged 1 commit into from
Feb 22, 2015

Conversation

GUI
Copy link
Contributor

@GUI GUI commented Feb 22, 2015

Each time nginx was reloaded (via the HUP signal), it was opening new handles to /dev/urandom for each worker process, but failing to close the old unused ones. So if you had 4 worker processes, after 3 reloads, you'd have 16 total handles to /dev/urandom open with 12 of those being unused. This led to an indefinite leaking of file descriptors on the nginx master process, which could eventually culminate in "too many files open" errors killing nginx if you managed to reload nginx enough times to hit your system file descriptor limit.

This shifts the /dev/urandom opening from the init_module into the init_process callback so that each worker process opens its own files. This then allows us to properly close those file descriptors each time a worker exits on reload via the exit_process callback.

I'm not exactly sure how to test this within the context of Test::Nginx, but in some manual testing, this does seem to fix the file descriptor leak across repeated reloads.

Each time nginx was reloaded (via the HUP signal), it was opening new
handles to /dev/urandom for each worker process, but failing to close
the old unused ones. So if you had 4 worker processes, after 3 reloads,
you'd have 16 total handles to /dev/urandom open with 12 of those being
unused. This led to an indefinite leaking of file descriptors on the
nginx master process, which could eventually culminate in "too many
files open" errors killing nginx if you managed to reload nginx enough
times to hit your system file descriptor limit.

This shifts the /dev/urandom opening from the init_module into the
init_process callback so that each worker process opens its own files.
This then allows us to properly close those file descriptors each time a
worker exits on reload via the exit_process callback.

I'm not exactly sure how to test this within the context of Test::Nginx,
but in some manual testing, this does seem to fix the file descriptor
leak across repeated reloads.
@hacfi
Copy link

hacfi commented Feb 22, 2015

👍 looks good

@streadway
Copy link
Owner

Good find!

streadway pushed a commit that referenced this pull request Feb 22, 2015
Fix file descriptor leak on /dev/urandom each time nginx reloads
@streadway streadway merged commit f1c197c into streadway:master Feb 22, 2015
@GUI
Copy link
Contributor Author

GUI commented Feb 22, 2015

Thanks for the quick merge!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants