Backport #2962

fork + Array#shuffle segfault

Added by normalperson (Eric Wong) over 10 years ago. Updated over 9 years ago.



Using Array#shuffle after forking causes a segmentation fault
with 1.9.1-p378 and 1.9.2dev (2010-02-26 trunk 1971). Calling
Kernel.rand immediately after forking fixes the issue, but
is suboptimal.

Attach is a proposed fix to rb_reset_random_seed() to reinitialize the random
seed after resetting.

$ cat shuffle.rb
pid = fork do
p Process.waitpid2(pid)

$ ~/ruby-1.9/bin/ruby shuffle.rb
shuffle.rb:2: [BUG] Segmentation fault
ruby 1.9.1p378 (2010-01-10 revision 26273) [x86_64-linux]

-- control frame ----------
c:0007 p:---- s:0017 b:0017 l:000016 d:000016 CFUNC :shuffle
c:0006 p:0018 s:0014 b:0014 l:000598 d:000013 BLOCK shuffle.rb:2
c:0005 p:---- s:0012 b:0012 l:000011 d:000011 FINISH
c:0004 p:---- s:0010 b:0010 l:000009 d:000009 CFUNC :fork
c:0003 p:0009 s:0007 b:0007 l:000598 d:000260 EVAL shuffle.rb:1
c:0002 p:---- s:0004 b:0004 l:000003 d:000003 FINISH
c:0001 p:0000 s:0002 b:0002 l:000598 d:000598 TOP

-- Ruby level backtrace information-----------------------------------------
shuffle.rb:2:in shuffle'
block in '
shuffle.rb:1:in fork'

-- C level backtrace information -------------------------------------------
0x4eaefb /home/ew/ruby-1.9/bin/ruby(rb_vm_bugreport+0x3b) [0x4eaefb]
0x51975e /home/ew/ruby-1.9/bin/ruby [0x51975e]
0x5198c1 /home/ew/ruby-1.9/bin/ruby(rb_bug+0xb1) [0x5198c1]
0x49526f /home/ew/ruby-1.9/bin/ruby [0x49526f]
0x2b18ec32ba80 /lib/ [0x2b18ec32ba80]
0x4687ba /home/ew/ruby-1.9/bin/ruby [0x4687ba]
0x468986 /home/ew/ruby-1.9/bin/ruby [0x468986]
0x4faef6 /home/ew/ruby-1.9/bin/ruby [0x4faef6]
0x4faf61 /home/ew/ruby-1.9/bin/ruby [0x4faf61]
0x4d8970 /home/ew/ruby-1.9/bin/ruby [0x4d8970]
0x4e6a00 /home/ew/ruby-1.9/bin/ruby [0x4e6a00]
0x4dba34 /home/ew/ruby-1.9/bin/ruby [0x4dba34]
0x4e0beb /home/ew/ruby-1.9/bin/ruby [0x4e0beb]
0x4e88a6 /home/ew/ruby-1.9/bin/ruby(rb_yield+0x926) [0x4e88a6]
0x418a39 /home/ew/ruby-1.9/bin/ruby(rb_protect+0xd9) [0x418a39]
0x465b50 /home/ew/ruby-1.9/bin/ruby [0x465b50]
0x4d8970 /home/ew/ruby-1.9/bin/ruby [0x4d8970]
0x4e6a00 /home/ew/ruby-1.9/bin/ruby [0x4e6a00]
0x4dba34 /home/ew/ruby-1.9/bin/ruby [0x4dba34]
0x4e0beb /home/ew/ruby-1.9/bin/ruby [0x4e0beb]
0x4e0db9 /home/ew/ruby-1.9/bin/ruby(rb_iseq_eval_main+0xa9) [0x4e0db9]
0x41951c /home/ew/ruby-1.9/bin/ruby(ruby_exec_node+0xac) [0x41951c]
0x41ab13 /home/ew/ruby-1.9/bin/ruby(ruby_run_node+0x33) [0x41ab13]
0x417f7d /home/ew/ruby-1.9/bin/ruby(main+0x4d) [0x417f7d]
0x2b18ece201a6 /lib/ [0x2b18ece201a6]
0x417e69 /home/ew/ruby-1.9/bin/ruby [0x417e69]

You may encounter a bug of Ruby interpreter. Bug reports are welcome.
For details:

[24566, #]


shuffle.rb (65 Bytes) shuffle.rb program to reproduce error normalperson (Eric Wong), 03/15/2010 09:43 AM
0001-random-reinitialize-random-when-resetting.patch (722 Bytes) 0001-random-reinitialize-random-when-resetting.patch proposed patch to fix (seems to work, needs review) normalperson (Eric Wong), 03/15/2010 09:43 AM

Updated by naruse (Yui NARUSE) over 10 years ago

  • Status changed from Open to Assigned
  • Assignee set to shyouhei (Shyouhei Urabe)

trunk is fixed by r26936.
Please backport r26936.

Thank you for your report.


Updated by naruse (Yui NARUSE) over 10 years ago

  • Assignee changed from shyouhei (Shyouhei Urabe) to yugui (Yuki Sonoda)




Updated by yugui (Yuki Sonoda) over 10 years ago

  • Status changed from Assigned to Closed
  • % Done changed from 0 to 100

This issue was solved with changeset r28511.
Eric, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


Also available in: Atom PDF