Project

General

Profile

Actions

Backport #2962

closed

fork + Array#shuffle segfault

Added by normalperson (Eric Wong) about 14 years ago. Updated almost 13 years ago.

Status:
Closed
[ruby-core:28655]

Description

=begin
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
(1..10).to_a.shuffle
end
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' shuffle.rb:2:in block in '
shuffle.rb:1:in fork' shuffle.rb:1:in '

-- 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/libpthread.so.0 [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/libc.so.6(__libc_start_main+0xe6) [0x2b18ece201a6]
0x417e69 /home/ew/ruby-1.9/bin/ruby [0x417e69]

[NOTE]
You may encounter a bug of Ruby interpreter. Bug reports are welcome.
For details: http://www.ruby-lang.org/bugreport.html

[24566, #<Process::Status: pid 24566 SIGIOT (signal 6) (core dumped)>]
=end


Files

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
Actions #1

Updated by naruse (Yui NARUSE) about 14 years ago

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

=begin
trunk is fixed by r26936.
Please backport r26936.

Thank you for your report.
=end

Actions #2

Updated by naruse (Yui NARUSE) about 14 years ago

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

=begin

=end

Actions #3

Updated by yugui (Yuki Sonoda) over 13 years ago

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

=begin
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.

=end

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0