Project

General

Profile

Bug #13276

Dir.glob returns empty array when OS has no more file handles (expected exception)

Added by floehopper (James Mead) 4 months ago. Updated about 2 months ago.

Status:
Closed
Priority:
Normal
Target version:
-
ruby -v:
ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-darwin14]
[ruby-core:79899]

Description

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 <main>'
    from -e:1:in `upto'
    from -e:1:in `each'
    from -e:1:in `map'
    from -e:1:in `<main>'

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, #<Dir:bar>]
[2, #<Dir:bar>]
[3, #<Dir:bar>]
[4, #<Dir:bar>]
[5, #<Dir:bar>]
[6, #<Dir:bar>]
[7, #<Dir:bar>]
[8, #<Dir:bar>]
[9, #<Dir:bar>]
-e:1:in `initialize': Too many open files @ dir_initialize - bar (Errno::EMFILE)
    from -e:1:in `new'
    from -e:1:in `block in <main>'
    from -e:1:in `upto'
    from -e:1:in `each'
    from -e:1:in `map'
    from -e:1:in `<main>'

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.

Associated revisions

Revision 58156
Added by nobu (Nobuyoshi Nakada) 3 months ago

dir.c: err at glob failure

  • dir.c (glob_helper): raise a SystemCallError exception when opendir() failed, except for ENOENT, ENOTDIR, and EACCES. this behavior predates 1.0; the comments in glob.c claimed that glob() returned -1 on error but actualy the pointer to a global variable, then dir_glob() did check only -1 as the comments, and ignored actual errors. [Bug #13276]

dir.c: ruby_glob_funcs_t

History

#1 [ruby-core:79918] Updated by floehopper (James Mead) 4 months ago

  • Subject changed from Ruby Dir.glob returns empty array when too many open files to Ruby Dir.glob returns empty array when too many open files (silent failure)

#2 [ruby-core:79919] Updated by floehopper (James Mead) 4 months ago

  • Subject changed from Ruby Dir.glob returns empty array when too many open files (silent failure) to Ruby Dir.glob returns empty array when OS has no more file handles (silent failure)

#3 [ruby-core:79920] Updated by floehopper (James Mead) 4 months ago

  • Subject changed from Ruby Dir.glob returns empty array when OS has no more file handles (silent failure) to Dir.glob returns empty array when OS has no more file handles (silent failure)

#4 [ruby-core:79922] Updated by floehopper (James Mead) 4 months ago

  • Subject changed from Dir.glob returns empty array when OS has no more file handles (silent failure) to Dir.glob returns empty array when OS has no more file handles (expected exception)

#5 [ruby-core:79924] Updated by floehopper (James Mead) 4 months ago

  • Description updated (diff)

#7 [ruby-core:80226] Updated by nobu (Nobuyoshi Nakada) 3 months ago

  • Status changed from Open to Assigned
  • Assignee set to nobu (Nobuyoshi Nakada)

This bug predates 1.0, so it will be fixed by 2.5 but won't be backported.

#8 Updated by nobu (Nobuyoshi Nakada) 3 months ago

  • Status changed from Assigned to Closed

Applied in changeset trunk|r58156.


dir.c: err at glob failure

  • dir.c (glob_helper): raise a SystemCallError exception when opendir() failed, except for ENOENT, ENOTDIR, and EACCES. this behavior predates 1.0; the comments in glob.c claimed that glob() returned -1 on error but actualy the pointer to a global variable, then dir_glob() did check only -1 as the comments, and ignored actual errors. [Bug #13276]

dir.c: ruby_glob_funcs_t

#9 Updated by usa (Usaku NAKAMURA) about 2 months ago

  • Backport changed from 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: UNKNOWN to 2.2: WONTFIX, 2.3: REQUIRED, 2.4: REQUIRED

Also available in: Atom PDF