Issue #8594 has been updated by chris.frederick (Chris Frederick).


It does fail in 2.0.0p195.

Running this script against a local filesystem will probably not produce any errors.  I am using it to test networked filesystems during network disconnects.  My FS will frequently return EINVAL - you won't see any crashes unless that's happening for you too.

It'd be somewhat difficult to replicate my environment.  If staring at the code indicated by the stack trace isn't enlightening then let me know what debugging I can perform for you.  I can reproduce this about every 15 minutes in our lab.
----------------------------------------
Bug #8594: [BUG] rb_update_max_fd: invalid fd (4) given
https://bugs.ruby-lang.org/issues/8594#change-40367

Author: chris.frederick (Chris Frederick)
Status: Feedback
Priority: Normal
Assignee: 
Category: 
Target version: 
ruby -v: ruby 2.0.0p195 (2013-05-14) [i386-mingw32]
Backport: 1.9.3: UNKNOWN, 2.0.0: UNKNOWN


=begin

Note that I expect EINVAL when running this code.  Most of the time it is correctly handled by the rescue on line 108.  Occasionally, however, Ruby crashes.

I was originally experiencing this on 1.9.3p392; I upgraded to 2.0.0p195 but it did not resolve the problem.


The triggering code:

 100:# Try an file operation and print a single-character result to stdout.
 101:#
 102:# block - operation to perform.
 103:#
 104:# Returns nothing.
 105:def try
 106:  yield
 107:  print '.'
 108:rescue Errno::EINVAL
 109:  print 'i'
 110:  sleep 1
 111:rescue Errno::ENOENT
 112:  print 'n'
 113:  sleep 1
 114:rescue Errno::EACCES
 115:  print 'a'
 116:  sleep 1
 117:rescue Errno::EBADF
 118:  print 'b'
 119:  sleep 1
 120:rescue Errno::ENETDOWN
 121:  print 'd'
 122:  sleep 1
 123:rescue Errno::ERANGE
 124:  print 'r'
 125:  sleep 1
 126:end
 
 ...
 
 157:50.times do
 158:  filebase = 'shakeshake-' + Time.new.to_i.to_s
 159:  print "\ncreate " ; 50.times { |i| try { File.write('%s_%d' % [filebase, i], 'a' * 100_000) } }
 160:  print "\nrename " ; 50.times { |i| try { File.rename('%s_%d' % [filebase, i], 'deleteme_%d' % [i]) } }
 161:  print "\ndelete " ; 50.times { |i| try { File.unlink('deleteme_%d' % [i]) } }
 162:  puts
 163:end
 
It dies like so:

 create tcp_drop_test.rb:159: [BUG] rb_update_max_fd: invalid fd (4) given.
 ruby 2.0.0p195 (2013-05-14) [i386-mingw32]
 
 -- Control frame information -----------------------------------------------
 c:0009 p:---- s:0027 e:000026 CFUNC  :write
 c:0008 p:0030 s:0022 e:000021 BLOCK  tcp_drop_test.rb:159
 c:0007 p:0006 s:0020 e:000019 METHOD tcp_drop_test.rb:106
 c:0006 p:0007 s:0017 e:000016 BLOCK  tcp_drop_test.rb:159 [FINISH]
 c:0005 p:---- s:0014 e:000013 CFUNC  :times
 c:0004 p:0037 s:0011 e:000010 BLOCK  tcp_drop_test.rb:159 [FINISH]
 c:0003 p:---- s:0008 e:000007 CFUNC  :times
 c:0002 p:0282 s:0005 E:001558 EVAL   tcp_drop_test.rb:157 [FINISH]
 c:0001 p:0000 s:0002 E:001e84 TOP    [FINISH]
 
 tcp_drop_test.rb:157:in `<main>'
 tcp_drop_test.rb:157:in `times'
 tcp_drop_test.rb:159:in `block in <main>'
 tcp_drop_test.rb:159:in `times'
 tcp_drop_test.rb:159:in `block (2 levels) in <main>'
 tcp_drop_test.rb:106:in `try'
 tcp_drop_test.rb:159:in `block (3 levels) in <main>'
 tcp_drop_test.rb:159:in `write'
 
 -- C level backtrace information -------------------------------------------
 C:\Windows\SysWOW64\ntdll.dll(ZwWaitForSingleObject+0x15) [0x773AF8B1]
 C:\Windows\syswow64\kernel32.dll(WaitForSingleObjectEx+0x43) [0x75B41194]
 C:\Windows\syswow64\kernel32.dll(WaitForSingleObject+0x12) [0x75B41148]
 C:\Ruby200\bin\msvcrt-ruby200.dll(rb_vm_bugreport+0xa7) [0x668F69D7]
 C:\Ruby200\bin\msvcrt-ruby200.dll(rb_name_err_mesg_new+0x69d) [0x667BE2AD]
 C:\Ruby200\bin\msvcrt-ruby200.dll(rb_bug+0x2e) [0x667BF0AE]
 C:\Ruby200\bin\msvcrt-ruby200.dll(rb_update_max_fd+0x52) [0x667EC952]
 C:\Ruby200\bin\msvcrt-ruby200.dll(rb_update_max_fd+0xb9) [0x667EC9B9]
 C:\Ruby200\bin\msvcrt-ruby200.dll(rb_io_fptr_finalize+0x3ae) [0x667F30AE]
 C:\Ruby200\bin\msvcrt-ruby200.dll(rb_pipe+0xf1e) [0x667F864E]
 C:\Ruby200\bin\msvcrt-ruby200.dll(rb_pipe+0xfb4) [0x667F86E4]
 C:\Ruby200\bin\msvcrt-ruby200.dll(rb_error_arity+0x129) [0x668E1F89]
 C:\Ruby200\bin\msvcrt-ruby200.dll(rb_f_send+0xbd8) [0x668F1968]
 C:\Ruby200\bin\msvcrt-ruby200.dll(rb_vm_localjump_error+0x25ad) [0x668E69ED]
 C:\Ruby200\bin\msvcrt-ruby200.dll(rb_vm_localjump_error+0x6ce4) [0x668EB124]
 C:\Ruby200\bin\msvcrt-ruby200.dll(rb_yield+0x131) [0x668F3551]
 C:\Ruby200\bin\msvcrt-ruby200.dll(rb_parser_dump_tree+0xeef) [0x6680F35F]
 C:\Ruby200\bin\msvcrt-ruby200.dll(rb_error_arity+0x129) [0x668E1F89]
 C:\Ruby200\bin\msvcrt-ruby200.dll(rb_f_send+0xbd8) [0x668F1968]
 C:\Ruby200\bin\msvcrt-ruby200.dll(rb_vm_localjump_error+0x24fd) [0x668E693D]
 C:\Ruby200\bin\msvcrt-ruby200.dll(rb_vm_localjump_error+0x6ce4) [0x668EB124]
 C:\Ruby200\bin\msvcrt-ruby200.dll(rb_yield+0x131) [0x668F3551]
 C:\Ruby200\bin\msvcrt-ruby200.dll(rb_parser_dump_tree+0xeef) [0x6680F35F]
 C:\Ruby200\bin\msvcrt-ruby200.dll(rb_error_arity+0x129) [0x668E1F89]
 C:\Ruby200\bin\msvcrt-ruby200.dll(rb_f_send+0xbd8) [0x668F1968]
 C:\Ruby200\bin\msvcrt-ruby200.dll(rb_vm_localjump_error+0x24fd) [0x668E693D]
 C:\Ruby200\bin\msvcrt-ruby200.dll(rb_vm_localjump_error+0x6ce4) [0x668EB124]
 C:\Ruby200\bin\msvcrt-ruby200.dll(rb_iseq_eval_main+0x131) [0x668F39E1]
 C:\Ruby200\bin\msvcrt-ruby200.dll(rb_check_copyable+0x3721) [0x667C44E1]
 C:\Ruby200\bin\msvcrt-ruby200.dll(ruby_run_node+0x2d) [0x667C6A0D]
 [0x0040287F]
 [0x004013FA]
 C:\Windows\syswow64\kernel32.dll(BaseThreadInitThunk+0x12) [0x75B433AA]
 C:\Windows\SysWOW64\ntdll.dll(RtlInitializeExceptionChain+0x63) [0x773C9EF2]
 
 -- Other runtime information -----------------------------------------------
 
 * Loaded script: tcp_drop_test.rb
 
 * Loaded features:
 
 0 enumerator.so
 1 C:/Ruby200/lib/ruby/2.0.0/i386-mingw32/enc/encdb.so
 2 C:/Ruby200/lib/ruby/2.0.0/i386-mingw32/enc/iso_8859_1.so
 3 C:/Ruby200/lib/ruby/2.0.0/i386-mingw32/enc/trans/transdb.so
 4 C:/Ruby200/lib/ruby/2.0.0/i386-mingw32/rbconfig.rb
 5 C:/Ruby200/lib/ruby/2.0.0/rubygems/compatibility.rb
 6 C:/Ruby200/lib/ruby/2.0.0/rubygems/defaults.rb
 7 C:/Ruby200/lib/ruby/2.0.0/rubygems/deprecate.rb
 8 C:/Ruby200/lib/ruby/2.0.0/rubygems/errors.rb
 9 C:/Ruby200/lib/ruby/2.0.0/rubygems/version.rb
 10 C:/Ruby200/lib/ruby/2.0.0/rubygems/requirement.rb
 11 C:/Ruby200/lib/ruby/2.0.0/rubygems/platform.rb
 12 C:/Ruby200/lib/ruby/2.0.0/rubygems/specification.rb
 13 C:/Ruby200/lib/ruby/2.0.0/rubygems/exceptions.rb
 14 C:/Ruby200/lib/ruby/2.0.0/rubygems/defaults/operating_system.rb
 15 C:/Ruby200/lib/ruby/2.0.0/i386-mingw32/enc/utf_16le.so
 16 C:/Ruby200/lib/ruby/2.0.0/i386-mingw32/enc/trans/utf_16_32.so
 17 C:/Ruby200/lib/ruby/2.0.0/rubygems/core_ext/kernel_gem.rb
 18 C:/Ruby200/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb
 19 C:/Ruby200/lib/ruby/2.0.0/rubygems.rb
 20 C:/Ruby200/lib/ruby/2.0.0/rubygems/path_support.rb
 21 C:/Ruby200/lib/ruby/2.0.0/rubygems/dependency.rb
 22 C:/Ruby200/lib/ruby/2.0.0/i386-mingw32/enc/trans/single_byte.so
 23 C:/Ruby200/lib/ruby/2.0.0/thread.rb
 24 C:/Ruby200/lib/ruby/2.0.0/monitor.rb
 25 C:/Ruby200/lib/ruby/2.0.0/logger.rb
 26 C:/Ruby200/lib/ruby/gems/2.0.0/gems/net-ssh-2.6.7/lib/net/ssh/config.rb
 27 C:/Ruby200/lib/ruby/gems/2.0.0/gems/net-ssh-2.6.7/lib/net/ssh/errors.rb
 28 C:/Ruby200/lib/ruby/gems/2.0.0/gems/net-ssh-2.6.7/lib/net/ssh/loggable.rb
 29 C:/Ruby200/lib/ruby/2.0.0/i386-mingw32/socket.so
 30 C:/Ruby200/lib/ruby/2.0.0/socket.rb
 31 C:/Ruby200/lib/ruby/2.0.0/timeout.rb
 32 C:/Ruby200/lib/ruby/gems/2.0.0/gems/net-ssh-2.6.7/lib/net/ssh/version.rb
 33 C:/Ruby200/lib/ruby/gems/2.0.0/gems/net-ssh-2.6.7/lib/net/ssh/ruby_compat.rb
 34 C:/Ruby200/lib/ruby/2.0.0/i386-mingw32/digest.so
 35 C:/Ruby200/lib/ruby/2.0.0/digest.rb
 36 C:/Ruby200/lib/ruby/2.0.0/i386-mingw32/openssl.so
 37 C:/Ruby200/lib/ruby/2.0.0/openssl/bn.rb
 38 C:/Ruby200/lib/ruby/2.0.0/openssl/cipher.rb
 39 C:/Ruby200/lib/ruby/2.0.0/i386-mingw32/stringio.so
 40 C:/Ruby200/lib/ruby/2.0.0/openssl/config.rb
 41 C:/Ruby200/lib/ruby/2.0.0/openssl/digest.rb
 42 C:/Ruby200/lib/ruby/2.0.0/openssl/x509.rb
 43 C:/Ruby200/lib/ruby/2.0.0/openssl/buffering.rb
 44 C:/Ruby200/lib/ruby/2.0.0/i386-mingw32/fcntl.so
 45 C:/Ruby200/lib/ruby/2.0.0/openssl/ssl.rb
 46 C:/Ruby200/lib/ruby/2.0.0/openssl.rb
 47 C:/Ruby200/lib/ruby/gems/2.0.0/gems/net-ssh-2.6.7/lib/net/ssh/transport/openssl.rb
 48 C:/Ruby200/lib/ruby/gems/2.0.0/gems/net-ssh-2.6.7/lib/net/ssh/buffer.rb
 49 C:/Ruby200/lib/ruby/2.0.0/i386-mingw32/strscan.so
 50 C:/Ruby200/lib/ruby/gems/2.0.0/gems/net-ssh-2.6.7/lib/net/ssh/known_hosts.rb
 51 C:/Ruby200/lib/ruby/gems/2.0.0/gems/net-ssh-2.6.7/lib/net/ssh/transport/ctr.rb
 52 C:/Ruby200/lib/ruby/gems/2.0.0/gems/net-ssh-2.6.7/lib/net/ssh/transport/key_expander.rb
 53 C:/Ruby200/lib/ruby/gems/2.0.0/gems/net-ssh-2.6.7/lib/net/ssh/transport/identity_cipher.rb
 54 C:/Ruby200/lib/ruby/gems/2.0.0/gems/net-ssh-2.6.7/lib/net/ssh/transport/cipher_factory.rb
 55 C:/Ruby200/lib/ruby/gems/2.0.0/gems/net-ssh-2.6.7/lib/net/ssh/transport/constants.rb
 56 C:/Ruby200/lib/ruby/gems/2.0.0/gems/net-ssh-2.6.7/lib/net/ssh/transport/hmac/abstract.rb
 57 C:/Ruby200/lib/ruby/gems/2.0.0/gems/net-ssh-2.6.7/lib/net/ssh/transport/hmac/md5.rb
 58 C:/Ruby200/lib/ruby/gems/2.0.0/gems/net-ssh-2.6.7/lib/net/ssh/transport/hmac/md5_96.rb
 59 C:/Ruby200/lib/ruby/gems/2.0.0/gems/net-ssh-2.6.7/lib/net/ssh/transport/hmac/sha1.rb
 60 C:/Ruby200/lib/ruby/gems/2.0.0/gems/net-ssh-2.6.7/lib/net/ssh/transport/hmac/sha1_96.rb
 61 C:/Ruby200/lib/ruby/gems/2.0.0/gems/net-ssh-2.6.7/lib/net/ssh/transport/hmac/sha2_256.rb
 62 C:/Ruby200/lib/ruby/gems/2.0.0/gems/net-ssh-2.6.7/lib/net/ssh/transport/hmac/sha2_256_96.rb
 63 C:/Ruby200/lib/ruby/gems/2.0.0/gems/net-ssh-2.6.7/lib/net/ssh/transport/hmac/sha2_512.rb
 64 C:/Ruby200/lib/ruby/gems/2.0.0/gems/net-ssh-2.6.7/lib/net/ssh/transport/hmac/sha2_512_96.rb
 65 C:/Ruby200/lib/ruby/gems/2.0.0/gems/net-ssh-2.6.7/lib/net/ssh/transport/hmac/ripemd160.rb
 66 C:/Ruby200/lib/ruby/gems/2.0.0/gems/net-ssh-2.6.7/lib/net/ssh/transport/hmac/none.rb
 67 C:/Ruby200/lib/ruby/gems/2.0.0/gems/net-ssh-2.6.7/lib/net/ssh/transport/hmac.rb
 68 C:/Ruby200/lib/ruby/gems/2.0.0/gems/net-ssh-2.6.7/lib/net/ssh/transport/kex/diffie_hellman_group1_sha1.rb
 69 C:/Ruby200/lib/ruby/gems/2.0.0/gems/net-ssh-2.6.7/lib/net/ssh/transport/kex/diffie_hellman_group14_sha1.rb
 70 C:/Ruby200/lib/ruby/gems/2.0.0/gems/net-ssh-2.6.7/lib/net/ssh/transport/kex/diffie_hellman_group_exchange_sha1.rb
 71 C:/Ruby200/lib/ruby/gems/2.0.0/gems/net-ssh-2.6.7/lib/net/ssh/transport/kex/diffie_hellman_group_exchange_sha256.rb
 72 C:/Ruby200/lib/ruby/gems/2.0.0/gems/net-ssh-2.6.7/lib/net/ssh/transport/kex/ecdh_sha2_nistp256.rb
 73 C:/Ruby200/lib/ruby/gems/2.0.0/gems/net-ssh-2.6.7/lib/net/ssh/transport/kex/ecdh_sha2_nistp384.rb
 74 C:/Ruby200/lib/ruby/gems/2.0.0/gems/net-ssh-2.6.7/lib/net/ssh/transport/kex/ecdh_sha2_nistp521.rb
 75 C:/Ruby200/lib/ruby/gems/2.0.0/gems/net-ssh-2.6.7/lib/net/ssh/transport/kex.rb
 76 C:/Ruby200/lib/ruby/gems/2.0.0/gems/net-ssh-2.6.7/lib/net/ssh/transport/server_version.rb
 77 C:/Ruby200/lib/ruby/gems/2.0.0/gems/net-ssh-2.6.7/lib/net/ssh/transport/algorithms.rb
 78 C:/Ruby200/lib/ruby/gems/2.0.0/gems/net-ssh-2.6.7/lib/net/ssh/buffered_io.rb
 79 C:/Ruby200/lib/ruby/gems/2.0.0/gems/net-ssh-2.6.7/lib/net/ssh/authentication/constants.rb
 80 C:/Ruby200/lib/ruby/gems/2.0.0/gems/net-ssh-2.6.7/lib/net/ssh/connection/constants.rb
 81 C:/Ruby200/lib/ruby/gems/2.0.0/gems/net-ssh-2.6.7/lib/net/ssh/packet.rb
 82 C:/Ruby200/lib/ruby/2.0.0/i386-mingw32/zlib.so
 83 C:/Ruby200/lib/ruby/gems/2.0.0/gems/net-ssh-2.6.7/lib/net/ssh/transport/state.rb
 84 C:/Ruby200/lib/ruby/gems/2.0.0/gems/net-ssh-2.6.7/lib/net/ssh/transport/packet_stream.rb
 85 C:/Ruby200/lib/ruby/gems/2.0.0/gems/net-ssh-2.6.7/lib/net/ssh/verifiers/null.rb
 86 C:/Ruby200/lib/ruby/gems/2.0.0/gems/net-ssh-2.6.7/lib/net/ssh/verifiers/secure.rb
 87 C:/Ruby200/lib/ruby/gems/2.0.0/gems/net-ssh-2.6.7/lib/net/ssh/verifiers/strict.rb
 88 C:/Ruby200/lib/ruby/gems/2.0.0/gems/net-ssh-2.6.7/lib/net/ssh/verifiers/lenient.rb
 89 C:/Ruby200/lib/ruby/gems/2.0.0/gems/net-ssh-2.6.7/lib/net/ssh/transport/session.rb
 90 C:/Ruby200/lib/ruby/gems/2.0.0/gems/net-ssh-2.6.7/lib/net/ssh/prompt.rb
 91 C:/Ruby200/lib/ruby/gems/2.0.0/gems/net-ssh-2.6.7/lib/net/ssh/key_factory.rb
 92 C:/Ruby200/lib/ruby/2.0.0/i386-mingw32/dl.so
 93 C:/Ruby200/lib/ruby/2.0.0/i386-mingw32/fiddle.so
 94 C:/Ruby200/lib/ruby/2.0.0/fiddle/function.rb
 95 C:/Ruby200/lib/ruby/2.0.0/fiddle/closure.rb
 96 C:/Ruby200/lib/ruby/2.0.0/fiddle.rb
 97 C:/Ruby200/lib/ruby/2.0.0/dl.rb
 98 C:/Ruby200/lib/ruby/2.0.0/dl/callback.rb
 99 C:/Ruby200/lib/ruby/2.0.0/dl/stack.rb
 100 C:/Ruby200/lib/ruby/2.0.0/dl/value.rb
 101 C:/Ruby200/lib/ruby/2.0.0/dl/func.rb
 102 C:/Ruby200/lib/ruby/2.0.0/dl/pack.rb
 103 C:/Ruby200/lib/ruby/2.0.0/dl/struct.rb
 104 C:/Ruby200/lib/ruby/2.0.0/dl/cparser.rb
 105 C:/Ruby200/lib/ruby/2.0.0/dl/import.rb
 106 C:/Ruby200/lib/ruby/2.0.0/dl/types.rb
 107 C:/Ruby200/lib/ruby/gems/2.0.0/gems/net-ssh-2.6.7/lib/net/ssh/authentication/pageant.rb
 108 C:/Ruby200/lib/ruby/gems/2.0.0/gems/net-ssh-2.6.7/lib/net/ssh/authentication/agent/socket.rb
 109 C:/Ruby200/lib/ruby/gems/2.0.0/gems/net-ssh-2.6.7/lib/net/ssh/authentication/agent.rb
 110 C:/Ruby200/lib/ruby/gems/2.0.0/gems/net-ssh-2.6.7/lib/net/ssh/authentication/key_manager.rb
 111 C:/Ruby200/lib/ruby/gems/2.0.0/gems/net-ssh-2.6.7/lib/net/ssh/authentication/methods/abstract.rb
 112 C:/Ruby200/lib/ruby/gems/2.0.0/gems/net-ssh-2.6.7/lib/net/ssh/authentication/methods/publickey.rb
 113 C:/Ruby200/lib/ruby/gems/2.0.0/gems/net-ssh-2.6.7/lib/net/ssh/authentication/methods/hostbased.rb
 114 C:/Ruby200/lib/ruby/gems/2.0.0/gems/net-ssh-2.6.7/lib/net/ssh/authentication/methods/password.rb
 115 C:/Ruby200/lib/ruby/gems/2.0.0/gems/net-ssh-2.6.7/lib/net/ssh/authentication/methods/keyboard_interactive.rb
 116 C:/Ruby200/lib/ruby/gems/2.0.0/gems/net-ssh-2.6.7/lib/net/ssh/authentication/session.rb
 117 C:/Ruby200/lib/ruby/gems/2.0.0/gems/net-ssh-2.6.7/lib/net/ssh/connection/term.rb
 118 C:/Ruby200/lib/ruby/gems/2.0.0/gems/net-ssh-2.6.7/lib/net/ssh/connection/channel.rb
 119 C:/Ruby200/lib/ruby/gems/2.0.0/gems/net-ssh-2.6.7/lib/net/ssh/service/forward.rb
 120 C:/Ruby200/lib/ruby/gems/2.0.0/gems/net-ssh-2.6.7/lib/net/ssh/connection/session.rb
 121 C:/Ruby200/lib/ruby/gems/2.0.0/gems/net-ssh-2.6.7/lib/net/ssh.rb
 
 [NOTE]
 You may have encountered a bug in the Ruby interpreter or extension libraries.
 Bug reports are welcome.
 For details: http://www.ruby-lang.org/bugreport.html
 
 This application has requested the Runtime to terminate it in an unusual way.
 Please contact the application's support team for more information. 
=end



-- 
http://bugs.ruby-lang.org/