LoginSignup
1
0

More than 3 years have passed since last update.

hugoで’hugo server'でプレビューしようとしたらError: listen tcp ***: socket: too many open filesが出た時の対処方法

Posted at

hugo serverコマンド使用時の注意点

hugo serverで作っているwebページを確認しようとしたらこんなエラーがでた。

Serving pages from memory
Running in Fast Render Mode. For full rebuilds on change: hugo server --disableFastRender
Web Server is available at //localhost:49744/ (bind address 127.0.0.1)
Press Ctrl+C to stop
ERROR 2020/08/04 13:36:01 Error: listen tcp 127.0.0.1:49744: socket: too many open files

エラーをググるとファイル数を一気に開けないことで上記の症状が起こる模様

調べてみると、自分が作っているサイトに関しては
スクリーンショット 2020-08-04 13.46.29.png
14000オーバー。
これが原因。

自分の設定の確認方法

keineme% ulimit -n
12800
keineme% ulimit -a
core file size          (blocks, -c) unlimited
data seg size           (kbytes, -d) unlimited
file size               (blocks, -f) unlimited
max locked memory       (kbytes, -l) unlimited
max memory size         (kbytes, -m) unlimited
open files                      (-n) 12800←ここが足りてない
pipe size            (512 bytes, -p) 1
stack size              (kbytes, -s) 65532
cpu time               (seconds, -t) unlimited
max user processes              (-u) 2784
virtual memory          (kbytes, -v) unlimited

対応方法

/Library/LaunchDaemons/limit.maxfiles.plist
ここにファイルを作成する。

limit.macfikes.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>65000</string> // ここの数字は扱う数より大きければよい
        <string>65000</string> // 同様
      </array>
      <key>RunAtLoad</key>
      <true/>
      <key>ServiceIPC</key>
      <false/>
    </dict>
  </plist>

このファイルを保存してOS再起動。
再起動して再度コマンド入力。

keineme% ulimit -a
core file size          (blocks, -c) unlimited
data seg size           (kbytes, -d) unlimited
file size               (blocks, -f) unlimited
max locked memory       (kbytes, -l) unlimited
max memory size         (kbytes, -m) unlimited
open files                      (-n) 65000
pipe size            (512 bytes, -p) 1
stack size              (kbytes, -s) 65532
cpu time               (seconds, -t) unlimited
max user processes              (-u) 2784
virtual memory          (kbytes, -v) unlimited

再度hugo serverを入力してプレビューがうまくいくことを確認する。

Linuxでも同様の状況が発生するとのことで同じ項目あたりで調べてみるとよいみたい。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0