LoginSignup
0
0

More than 1 year has passed since last update.

Goのfreshで出るエラー inotify_init: too many open files の解決方法

Last updated at Posted at 2021-06-19

Goのプロジェクトを、Docker上でfreshでホットリロードさせたかった

:
app_1    | 10:47:32 watcher     | Watching hoge....
app_1    | 10:47:32 watcher     | Watching fuga......
app_1    | inotify_init: too many open files

の流れで落ちました。
freshを切るとエラーが出ないことを確認し、freshのホットリロード用で監視するファイルが多すぎてエラーが出ているようでした。

解決方法 1

ファイルの開ける数が、どうも初期設定だと128までの模様。

$ sudo emacs /etc/sysctl.conf

sysctl.confを開いて、fs.inotify.max_user_instancesを探します。
既に項目があれば、

fs.inotify.max_user_instances = 1024

に値を置き換えます。
項目が無ければ、追記しましょう。
(私はありませんでした)

最後に、設定ファイルを読み直します。

$ sudo sysctl -p
$ sudo sysctl -a

これで解決しました。

解決方法 2

巨大外部ライブラリ等をホットリロード用に監視すると、余裕で1024ファイル超えます。
それらの監視も必要なのであれば、解決方法1のファイル数を増やしましょう。
明らかに監視する必要のないファイルがある場合は、以下のように設定ファイルを置いて監視するファイルを制限しましょう。

freshコマンドを実行するディレクトリに設定ファイルを置きます。

fresh.conf
root:              ./
tmp_path:          ./tmp
build_name:        api
valid_ext:         .go, .tpl, .tmpl, .html
no_rebuild_ext:    .tpl, .tmpl, .html
ignored:           ./vendor, tmp
build_delay:       600
colors:            1

公式の例から引用しています。
その他コンフィグの値は公式リポジトリのREADMEに簡単な例があります。
gravityblast/fresh

参考

issue #44

0
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
0
0