`close': Bad file descriptor - filename (Errno::EBADF)

Discussion in 'Ruby' started by Simon Strandgaard, Feb 16, 2004.

  1. While upgrading rubicon from 1.6 to 1.8, I bumped into
    this problem in the builtin/TestIO.rb file.
    http://rubyforge.org/cgi-bin/viewcvs/cgi/viewcvs.cgi/rubicon/builtin/TestIO.rb?cvsroot=rubytests


    I have extracted the code which reproduces the problem.
    Any ideas on how to solve it, would be nice.


    server> rm testtest
    server> ruby a.rb
    a.rb:5:in `close': Bad file descriptor - testtest (Errno::EBADF)
    from a.rb:5:in `open'
    from a.rb:5
    server> expand -t2 a.rb
    file = "testtest"
    File.open(file, "w") do |f|
    10.times { |i| f.printf "%02d: This is a line\n", i }
    end
    File.open(file, "w") do |f|
    io = IO.new(f.fileno, "w")
    io << 1 << "\n" << "dummy" << "\n" << "cat\n"
    io.close
    end
    server>

    --
    Simon Strandgaard
     
    Simon Strandgaard, Feb 16, 2004
    #1
    1. Advertising

  2. Hi,

    In message "`close': Bad file descriptor - filename (Errno::EBADF)"
    on 04/02/16, Simon Strandgaard <> writes:

    |While upgrading rubicon from 1.6 to 1.8, I bumped into
    |this problem in the builtin/TestIO.rb file.
    |http://rubyforge.org/cgi-bin/viewcvs/cgi/viewcvs.cgi/rubicon/builtin/TestIO.rb?cvsroot=rubytests

    It's a bug in rubicon. Try test suites bundled with 1.8.1 or later.

    |File.open(file, "w") do |f|
    | io = IO.new(f.fileno, "w")
    | io << 1 << "\n" << "dummy" << "\n" << "cat\n"
    | io.close <= close io here.
    |end <= open close io at the end of block (i.e. double close)

    matz.
     
    Yukihiro Matsumoto, Feb 16, 2004
    #2
    1. Advertising

  3. On Mon, 16 Feb 2004 22:51:36 +0900, Yukihiro Matsumoto wrote:
    > on 04/02/16, Simon Strandgaard <> writes:
    >
    > |While upgrading rubicon from 1.6 to 1.8, I bumped into
    > |this problem in the builtin/TestIO.rb file.
    > |http://rubyforge.org/cgi-bin/viewcvs/cgi/viewcvs.cgi/rubicon/builtin/TestIO.rb?cvsroot=rubytests
    >
    > It's a bug in rubicon. Try test suites bundled with 1.8.1 or later.

    [snip code]
    >


    Chad Fowler and I are working on upgrading rubicon for ruby-1.8.1.
    We have made a transition from rubyunit to now use testunit.

    I am working with the CVS version (I don't think there is a newer rubicon
    suite?) ;-)

    You can see the pending bugs here:
    http://rubyforge.org/tracker/?func=browse&group_id=179&atid=751
    Please comment on these :)


    The code which I am looking at is

    def test_LSHIFT # '<<'
    File.open(@file, "w") do |file|
    io = IO.new(file.fileno, "w")
    io << 1 << "\n" << Dummy.new << "\n" << "cat\n"
    io.close
    end
    expected = [ "1\n", "dummy\n", "cat\n"]
    IO.foreach(@file) do |line|
    assert_equal(expected.shift, line)
    end
    assert_equal([], expected)
    end

    Why make an instance of the IO class, when its the '<<' leftshift
    operator we want to test?

    --
    Simon Strandgaard
     
    Simon Strandgaard, Feb 16, 2004
    #3
  4. On Mon, 16 Feb 2004 17:02:50 +0100, Simon Strandgaard wrote:

    > Chad Fowler and I are working on upgrading rubicon for ruby-1.8.1.
    > We have made a transition from rubyunit to now use testunit.
    >
    > You can see the pending bugs here:
    > http://rubyforge.org/tracker/?func=browse&group_id=179&atid=751
    > Please comment on these :)
    >


    Ok I have one last problem with Bad File Descriptor.
    The source code for TestIO.rb is here:
    http://rubyforge.org/cgi-bin/viewcvs/cgi/viewcvs.cgi/rubicon/builtin/TestIO.rb?cvsroot=rubytests


    server> ruby TestIO.rb
    Loaded suite TestIO
    Started
    ..S.....E....S......S....................................
    Finished in 0.833549 seconds.

    1) Error:
    test_closed?(TestIO):
    Errno::EBADF: Bad file descriptor - _test/_99lines
    TestIO.rb:19:in `close'
    TestIO.rb:19:in `open'
    TestIO.rb:19:in `setup'

    53 tests, 1242 assertions, 0 failures, 1 errors
    server>

    --
    Simon Strandgaard
     
    Simon Strandgaard, Feb 16, 2004
    #4
  5. On Mon, 16 Feb 2004 18:09:08 +0100, Simon Strandgaard wrote:
    >
    > Ok I have one last problem with Bad File Descriptor.

    [snip]

    Solved.. It was a typo I had made, writing 'clone' where I meant 'close'.


    Sorry for the noise.

    --
    Simon Strandgaard
     
    Simon Strandgaard, Feb 16, 2004
    #5
    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. rbt
    Replies:
    4
    Views:
    1,059
  2. joblack

    Errno 9] Bad file descriptor

    joblack, Jul 12, 2010, in forum: Python
    Replies:
    9
    Views:
    6,374
  3. Mr_Tibs

    can't rescue Errno::EBADF

    Mr_Tibs, Sep 5, 2007, in forum: Ruby
    Replies:
    3
    Views:
    185
    Nobuyoshi Nakada
    Sep 6, 2007
  4. Daniel Berger
    Replies:
    4
    Views:
    296
    Douglas Wells
    Feb 19, 2008
  5. Valerie Hollingsworth

    Bad file descriptor - connect(2) (Errno::EBADF)

    Valerie Hollingsworth, May 9, 2008, in forum: Ruby
    Replies:
    0
    Views:
    662
    Valerie Hollingsworth
    May 9, 2008
Loading...

Share This Page