Too many open files - getcwd (Errno::EMFILE)

Discussion in 'Ruby' started by sera@fhwang.net, Feb 4, 2005.

  1. Guest

    So I'm working on my wonky FileSystem library, and right now it makes a
    lot of calls to Dir.getwd. I find that if I use it enough -- right now
    I'm integrating it into my main web site's unit tests, all 500 of them
    -- then I get a traceback like this:

    /usr/local/lib/ruby/site_ruby/1.8/filesystem.rb:251:in
    `getwd'(TestArtbaseSubmissionPhaseChange): Too many open files - getcwd
    (Errno::EMFILE)
    from /usr/local/lib/ruby/site_ruby/1.8/filesystem.rb:251:in
    `absolute'
    from /usr/local/lib/ruby/site_ruby/1.8/filesystem.rb:154:in
    `fill_path'
    from ./test/ts_domain.rb:43:in `setup'
    from /usr/bin/runtest.rb:23:in `run'
    from /usr/bin/runtest.rb:33

    The ruby-talk archives lead me to believe that Errno::EMFILE is thrown
    when you have too many open files lying around, hence the error,
    obviously. This is easy enough for me to work around, but I'm curious:
    Why would Dir.getwd have this problem? Is it opening some files for
    some reason?
    , Feb 4, 2005
    #1
    1. Advertising

  2. wrote:
    > So I'm working on my wonky FileSystem library, and right now it makes

    a
    > lot of calls to Dir.getwd. I find that if I use it enough -- right

    now
    > I'm integrating it into my main web site's unit tests, all 500 of

    them
    > -- then I get a traceback like this:
    >
    > /usr/local/lib/ruby/site_ruby/1.8/filesystem.rb:251:in
    > `getwd'(TestArtbaseSubmissionPhaseChange): Too many open files -

    getcwd
    > (Errno::EMFILE)
    > from /usr/local/lib/ruby/site_ruby/1.8/filesystem.rb:251:in
    > `absolute'
    > from /usr/local/lib/ruby/site_ruby/1.8/filesystem.rb:154:in
    > `fill_path'
    > from ./test/ts_domain.rb:43:in `setup'
    > from /usr/bin/runtest.rb:23:in `run'
    > from /usr/bin/runtest.rb:33
    >
    > The ruby-talk archives lead me to believe that Errno::EMFILE is

    thrown
    > when you have too many open files lying around, hence the error,
    > obviously. This is easy enough for me to work around, but I'm

    curious:
    > Why would Dir.getwd have this problem? Is it opening some files for
    > some reason?


    I cannot duplicate this on Solaris or Windows with 1.8.2:

    irb(main):006:0> 10000.times{ Dir.getwd }
    => 10000
    irb(main):007:0> 100000.times{ Dir.getwd }
    => 100000

    There are no filehandles being opened in ruby_getcwd (in util.h) that I
    can see, just some xmalloc/xrealloc, which is freed before you get the
    result.

    Very strange.

    Regards,

    Dan
    Daniel Berger, Feb 4, 2005
    #2
    1. Advertising

  3. Guest

    Yeah, attempts to narrow it down were pretty difficult ... Every time I
    ran my 500 test cases, I got bit by that bug a couple of times, but it
    hit different test cases on different runs. So I just locally cached
    the value, calling Dir.getwd 1 time instead of a couple thousand, and
    it seems to be working fine now.
    , Feb 4, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. someone

    "To many files open error <EMFILE>" bug

    someone, Aug 17, 2006, in forum: C Programming
    Replies:
    8
    Views:
    602
    Dave Thompson
    Aug 28, 2006
  2. Richard
    Replies:
    2
    Views:
    1,774
    Richard
    Mar 11, 2010
  3. amos
    Replies:
    1
    Views:
    285
    Eric Hodel
    Jan 22, 2007
  4. Replies:
    2
    Views:
    343
  5. Jim Surname
    Replies:
    3
    Views:
    407
    Jim Surname
    Jan 25, 2008
Loading...

Share This Page