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

**URL:** <https://www.ruby-forum.com/t/bug-1338-kernel-select-crashes-when-many-files-are-opened/164338>\
**Category:** Development\
**Created:** [March 31, 2009, 10:43am UTC](https://www.ruby-forum.com/t/bug-1338-kernel-select-crashes-when-many-files-are-opened/164338 "2009-03-31T10:43:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kengo\_Matsuyama](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/fbc32d/32.png) [@Kengo\_Matsuyama](https://www.ruby-forum.com/u/Kengo_Matsuyama)\
**Post date:** [March 31, 2009, 10:43am UTC](https://www.ruby-forum.com/t/bug-1338-kernel-select-crashes-when-many-files-are-opened/164338/1 "2009-03-31T10:43:09Z")

</div>

Bug #1338: Kernel#select crashes when many files are opened  
[http://redmine.ruby-lang.org/issues/show/1338](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:in `select’

## – 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](http://www.ruby-lang.org/bugreport.html)

Aborted

---

<div class="post-metadata">

**Author:** ![Kengo\_Matsuyama](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/fbc32d/32.png) [@Kengo\_Matsuyama](https://www.ruby-forum.com/u/Kengo_Matsuyama)\
**Post date:** [April 1, 2009, 6:58am UTC](https://www.ruby-forum.com/t/bug-1338-kernel-select-crashes-when-many-files-are-opened/164338/2 "2009-04-01T06:58:13Z")

</div>

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](http://redmine.ruby-lang.org/issues/show/1338)
