From: james@... Date: 2017-03-05T13:14:23+00:00 Subject: [ruby-core:79924] [Ruby trunk Bug#13276] Dir.glob returns empty array when OS has no more file handles (expected exception) Issue #13276 has been updated by James Mead. Description updated ---------------------------------------- Bug #13276: Dir.glob returns empty array when OS has no more file handles (expected exception) https://bugs.ruby-lang.org/issues/13276#change-63354 * Author: James Mead * Status: Open * Priority: Normal * Assignee: * Target version: * ruby -v: ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-darwin14] * Backport: 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: UNKNOWN ---------------------------------------- The following terminal session demonstrates how `Dir.glob` returns an empty array when the OS has run out of file handles; whereas `File.new` raises a `Errno::EMFILE` exception. I would expect `Dir.glob` to fail fast in a similar way to `File.new`. ~~~ $ mkdir /tmp/ruby-dir-glob-returns-empty-array-when-too-many-open-files $ cd /tmp/ruby-dir-glob-returns-empty-array-when-too-many-open-files $ touch foo $ ulimit -n 16 $ ruby -e "1.upto(16).map { |i| p [i, Dir.glob('*')]; File.new('foo') }" [1, ["foo"]] [2, ["foo"]] [3, ["foo"]] [4, ["foo"]] [5, ["foo"]] [6, ["foo"]] [7, ["foo"]] [8, ["foo"]] [9, ["foo"]] [10, []] # Dir.glob returns empty array and does not raise exception -e:1:in `initialize': Too many open files @ rb_sysopen - foo (Errno::EMFILE) from -e:1:in `new' from -e:1:in `block in
' from -e:1:in `upto' from -e:1:in `each' from -e:1:in `map' from -e:1:in `
' ~~~ The following is a counter example which shows how `Dir.new` raises an exception under the same conditions. ~~~ $ mkdir /tmp/ruby-dir-new-raises-exception-when-too-many-files-open $ cd /tmp/ruby-dir-new-raises-exception-when-too-many-files-open $ touch foo $ mkdir bar $ ulimit -n 16 $ ruby -e "1.upto(16).map { |i| p [i, Dir.new('bar')]; File.new('foo') }" [1, #] [2, #] [3, #] [4, #] [5, #] [6, #] [7, #] [8, #] [9, #] -e:1:in `initialize': Too many open files @ dir_initialize - bar (Errno::EMFILE) from -e:1:in `new' from -e:1:in `block in
' from -e:1:in `upto' from -e:1:in `each' from -e:1:in `map' from -e:1:in `
' ~~~ This is what I would expect for `Dir.glob`, i.e. I would expect an exception like this: `Too many open files @ dir_s_glob (Errno::EMFILE)` in the first example. -- https://bugs.ruby-lang.org/ Unsubscribe: