From: "jonforums (Jon Forums)" Date: 2012-04-23T02:01:50+09:00 Subject: [ruby-core:44538] [ruby-trunk - Bug #6228] [mingw] Errno::EBADF in ruby/test_io.rb on ruby_1_9_3 Issue #6228 has been updated by jonforums (Jon Forums). mame (Yusuke Endoh) wrote: > jonforums (Jon Forums) wrote: > > Why is the following > > > > ensure > > fds.each {|fd| IO.for_fd(fd).close rescue next} > > > > wrong usage of IO.for_fd? > > f = open("...") # this first IO has a fd X which is opened now. > IO.for_fd(f.fileno) # this second IO also has the fd X. > GC.start # the second IO is GC'ed; the fd X is auto-closed. > f.close # this attempts to close the fd X, but it is already closed => Errno::EBADF > > > Specifically, is there another style of explicit recycling of fds that doesn't require starting a GC cycle? > > Call IO#close explicitly. Endoh-san, thank you. I understand. Why do you think the same incorrect test code fails (consistently, not intermittently) on windows when only using -DFD_SETSIZE, but doesn't appear to fail on *nix? On Arch, I've not been able to repro when building using -DFD_SETSIZE=32767. This may indicate a lurking weakness in an _WIN32 MRI codepath (or winsock2 peculiarity) that doesn't exist (or does a better job of hiding) on *nix. FYI, there's another recent issue on windows in which -DFD_SETSIZE=32767 exposes a SEGV with EventMachine with a simple `EM.run {}`. By default, EM sets FD_SETSIZE to 1024. Rebuilding ruby on windows without the FD_SETSIZE override fixes the SEGV. The EM issue is a separate issue than this one, but may be related. I haven't started investigating, so FYI. I will test again on ruby_1_9_3 and trunk with the suggested patch and reply if errors persist. Jon ---------------------------------------- Bug #6228: [mingw] Errno::EBADF in ruby/test_io.rb on ruby_1_9_3 https://bugs.ruby-lang.org/issues/6228#change-26088 Author: jonforums (Jon Forums) Status: Assigned Priority: Normal Assignee: nobu (Nobuyoshi Nakada) Category: test Target version: 1.9.3 ruby -v: ruby 1.9.3p172 (2012-03-30 revision 35179) [i386-mingw32] On Win7 32bit built with MinGW 4.6.2 using the RubyInstaller build recipes, I get the following test error: sh-3.1$ ruby --version ruby 1.9.3p172 (2012-03-30 revision 35179) [i386-mingw32] sh-3.1$ make test-all TESTS='openssl fiddle psych zlib io json mkmf pathname stringio erb fileutils ruby/test_io.rb ruby/test_io_m17n.rb ruby/test_file.rb' 7) Error: test_lines(TestIO): Errno::EBADF: Bad file descriptor c:/Users/Jon/Documents/RubyDev/ruby-git/test/ruby/test_io.rb:33:in `close' c:/Users/Jon/Documents/RubyDev/ruby-git/test/ruby/test_io.rb:33:in `rescue in block in pipe' c:/Users/Jon/Documents/RubyDev/ruby-git/test/ruby/test_io.rb:30:in `block in pipe' -- http://bugs.ruby-lang.org/