Skip to content

Instantly share code, notes, and snippets.

@jcsrb
Last active June 21, 2020 19:56
Show Gist options
  • Save jcsrb/4654463 to your computer and use it in GitHub Desktop.
Save jcsrb/4654463 to your computer and use it in GitHub Desktop.
if you get "socket() failed (24: Too many open files) while connecting to upstream" on nginx on MacOS
echo 'kern.maxfiles=20480' | sudo tee -a /etc/sysctl.conf
echo -e 'limit maxfiles 8192 20480\nlimit maxproc 1000 2000' | sudo tee -a /etc/launchd.conf
echo 'ulimit -n 4096' | sudo tee -a /etc/profile

Notes:

  • You will need to restart for these changes to take effect.
  • AFAIK you can no longer set limits to 'unlimited' under OS X
  • launchctl maxfiles are bounded by sysctl maxfiles, and therefore cannot exceed them
  • sysctl seems to inherit kern.maxfilesperproc from launchctl maxfiles
  • ulimit seems to inherit it's 'open files' value from launchctl by default
  • you can set a custom ulimit within /etc/profile, or ~/.profile ; while this isn't required I've provided an example
  • Be cautious when setting any of these values to a very high number when compared with their default - the features exist stability/security. I've taken these example numbers that I believe to be reasonable, written on other websites.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment