[Bug #1338] Kernel#select crashes when many files are opened


#1

Bug #1338: Kernel#select crashes when many files are opened
http://redmine.ruby-lang.org/issues/show/1338

e$B5/I<<Te(B: Kengo Matsuyama
e$B%9%F!<%?%9e(B: Open, e$BM%@hEYe(B: Normal
ruby -v: ruby 1.9.2dev (2009-03-31 trunk 23101) [i686-linux]

e$B0J2<$N%3!<%I$,%/%i%C%7%e$7$^$9!#e(B

Process.setrlimit(Process::RLIMIT_NOFILE, 2048)
fd = 2000.times.map { open("/bin/ls") }
select([fd.last], [], [], 0)

e$BE:IU$7$?%Q%C%A$G<j85$N4D6-$G$OF0$/$h$&$K$J$j$^$7$?$,!"e(B
e$BB>$N4D6-e(B(win32 e$B$H$+e(B)e$B$G$NF0:n$OJ,$+$i$J$$$G$9!#e(B

e$B$^$?!"6qBNE*$J:F8=%3!<%I$O:n$l$J$+$C$?$N$G$9$,!"e(B
thread.c e$B$Ne(B do_select() e$B$Ne(B orig_read, orig_write,
orig_except e$B$N07$$$O!"e(B
e$B%P%0$r0z$-5/$3$7$=$&$G$9!#e(B(fd_set e$B7?$r$=$N$^$^;H$C$F$$$ke(B)

e$B0J2<$O%/%i%C%7%e;~$N%m%0$G$9!#e(B

$ ./ruby -e ‘Process.setrlimit(Process::RLIMIT_NOFILE, 2048); fd =
2000.times.map { open("/bin/ls") }; select([fd.last], [], [], 0)’
-e:1: [BUG] Segmentation fault
ruby 1.9.2dev (2009-03-31 trunk 23101) [i686-linux]

– control frame ----------
c:0004 p:---- s:0014 b:0014 l:000013 d:000013 CFUNC :select
c:0003 p:0072 s:0007 b:0007 l:00199c d:000e68 EVAL -e:1
c:0002 p:---- s:0004 b:0004 l:000003 d:000003 FINISH
c:0001 p:0000 s:0002 b:0002 l:00199c d:00199c TOP :17

-e:1:in <main>' -e:1:inselect’

– C level backtrace information

0x81591a5 ./ruby(rb_vm_bugreport+0xb5) [0x81591a5]
0x819458e ./ruby [0x819458e]
0x8194628 ./ruby(rb_bug+0x28) [0x8194628]
0x80f2ef5 ./ruby [0x80f2ef5]
0xb7f8640c [0xb7f8640c]
0xb7e0f826 /lib/i686/cmov/libc.so.6(cfree+0x96) [0xb7e0f826]
0x8159c09 ./ruby(rb_fd_term+0x19) [0x8159c09]
0x80709d0 ./ruby [0x80709d0]
0x805c92c ./ruby(rb_ensure+0x9c) [0x805c92c]
0x8070bf4 ./ruby [0x8070bf4]
0x81451ad ./ruby [0x81451ad]
0x8156a06 ./ruby [0x8156a06]
0x8149c9b ./ruby [0x8149c9b]
0x81506a2 ./ruby [0x81506a2]
0x8150913 ./ruby(rb_iseq_eval_main+0x1a3) [0x8150913]
0x805ce07 ./ruby(ruby_exec_node+0x97) [0x805ce07]
0x805e596 ./ruby(ruby_run_node+0x46) [0x805e596]
0x805c100 ./ruby(main+0x60) [0x805c100]
0xb7db5455 /lib/i686/cmov/libc.so.6(__libc_start_main+0xe5) [0xb7db5455]
0x805c001 ./ruby [0x805c001]

[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

Aborted


#2

e$B%A%1%C%He(B #1338 e$B$,99?7$5$l$^$7$?!#e(B (by Yukihiro M.)

e$B%9%F!<%?%9e(B Opene$B$+$ie(BClosede$B$KJQ99e(B
e$B?JD=e(B % 0e$B$+$ie(B100e$B$KJQ99e(B

Applied in changeset r23109.

http://redmine.ruby-lang.org/issues/show/1338