AR ホームベーカリー

オイラのアウトプット用ホームベーカリー!

Unable to monitor directories for changes because iNotify max watches exceeded.

RAILS_ROOT で rails c したらエラーがでるー、と言われたやつ。 実際のエラーはこう。

/RAILS_ROOT/vendor/bundle/ruby/3.1.0/gems/listen-3.7.1/lib/listen/adapter/linux.rb:32:in `rescue in _configure': Unable to monitor directories for changes because iNotify max watches exceeded. See https://github.com/guard/listen/blob/master/README.md#increasing-the-amount-of-inotify-watchers .
 (Listen::Error::INotifyMaxWatchesExceeded)

全部以下に書いてある。

github.com

今回は AmazonLinux2 環境で RHEL の系譜なので以下を実行する。

[user@localhost ~]$ sudo sh -c "echo fs.inotify.max_user_watches=524288 >> /etc/sysctl.conf"
[user@localhost ~]$ sudo sysctl -p

inotify ってファイル監視の通知とかじゃなかったっけ……、と思ってたけど合ってた。

qiita.com

これ、たしかディレクトリを再帰的に監視しない、とかいうアレだった気がする。 ので、コンソール起動タイミングで RAILS_ROOT 以下どこかのディレクトリで、 inotify の監視数を超えるイベントが起こっているのだと思う。

Listen uses inotify by default on Linux to monitor directories for changes. It's not uncommon to encounter a system limit on the number of files you can monitor. For example, Ubuntu Lucid's (64bit) inotify limit is set to 8192.

Listen は、デフォルトで Linux の inotify を使用してディレクトリの変更を監視します。監視できるファイル数のシステム制限に遭遇することは珍しくありません。たとえば、Ubuntu Lucid (64 ビット) の inotify 制限は 8192 に設定されています。

https://github.com/guard/listen/blob/master/README.md#the-technical-details

ファイルシステム周りの問題、忘れた頃に出てくるのでなかなか思い出せないんだけど、シュッと対応できたのでよかったね。