16
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Errno::EMFILE: Too many open files - getcwd に悩まされた時

Posted at

Macのローカルで稀によく落ちるspecの原因調査の為に、csv絡みのrspecを走らせていたら、エラーが発生するようになってしまった。

An error occurred
  Errno::EMFILE: Too many open files - getcwd
  occurred at /foo/project_root/vendor/bundle/gems/rspec-core-2.99.2/lib/rspec/core/formatters/base_formatter.rb:208:in `expand_path'

Macのファイルディスクリプタの上限は、初期値では256しかないので、プロセスが取り扱うファイルが多くなるとエラーが発生してしまう。

% ulimit -n
256

その他の上限値も合わせて確認する場合は以下のコマンドでいける。

% launchctl limit
        cpu         unlimited      unlimited
        filesize    unlimited      unlimited
        data        unlimited      unlimited
        stack       8388608        67104768
        core        0              unlimited
        rss         unlimited      unlimited
        memlock     unlimited      unlimited
        maxproc     709            1064
        maxfiles    256            unlimited

解決方法

limit -n で一時的に設定を変更する

% ulimit -n 1024
% ulimit -n
1024
16
10
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
16
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?