socket: too many open files When Starting Hugo on a Mac

Raising the macOS file descriptor limit so that hugo can start

* This page contains promotional content

When I tried to run a certain theme with Hugo on MacOS Sierra, the error below appeared and it would not start

Error: listen tcp 127.0.0.1:1313: socket: too many open files

Looking into it, it turned out that the ulimit on the Mac needs to be changed, and I solved it by referring to macOS Sierraでulimitを変更する方法 - Carpe Diem (in Japanese).

Changing the ulimit

# cat /Library/LaunchDaemons/limit.maxfiles.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
  <dict>
    <key>Label</key>
    <string>limit.maxfiles</string>
    <key>ProgramArguments</key>
    <array>
      <string>launchctl</string>
      <string>limit</string>
      <string>maxfiles</string>
      <string>524288</string>
      <string>524288</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
    <key>ServiceIPC</key>
    <false/>
  </dict>
</plist>

# cat /Library/LaunchDaemons/limit.maxproc.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple/DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
  <dict>
    <key>Label</key>
    <string>limit.maxproc</string>
    <key>ProgramArguments</key>
    <array>
      <string>launchctl</string>
      <string>limit</string>
      <string>maxproc</string>
      <string>2048</string>
      <string>2048</string>
    </array>
    <key>RunAtLoad</key>
    <true />
    <key>ServiceIPC</key>
      <false />
  </dict>
</plist>
# chown root:wheel /Library/LaunchDaemons/limit.maxfiles.plist
# chown root:wheel /Library/LaunchDaemons/limit.maxproc.plist
# chmod 644 /Library/LaunchDaemons/limit.maxfiles.plist
# chmod 644 /Library/LaunchDaemons/limit.maxproc.plist

Restarting the Mac

Checking the change

$ ulimit -a
Maximum size of core files created                           (kB, -c) 0
Maximum size of a process’s data segment                     (kB, -d) unlimited
Maximum size of files created by the shell                   (kB, -f) unlimited
Maximum size that may be locked into memory                  (kB, -l) unlimited
Maximum resident set size                                    (kB, -m) unlimited
Maximum number of open file descriptors                          (-n) 524288
Maximum stack size                                           (kB, -s) 8192
Maximum amount of cpu time in seconds                   (seconds, -t) unlimited
Maximum number of processes available to a single user           (-u) 2048
Maximum amount of virtual memory available to the shell      (kB, -v) unlimited
mac 

See also