Project

General

Profile

ActionsLike0

Backport #5700

closed

fork {} segfaults during VM cleanup when run inside Fiber

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

Status:
Closed
Assignee:
-
[ruby-core:41456]

Description

The issue is very easy to reproduce:

Fiber.new do
  p Process.waitpid2(fork {})
end.resume

Parent process successfully exits, child process segfaults while
it is exiting.

Backtrace is attached (gdb_bt.txt)

MALLOC_CHECK_=3 with GNU libc malloc() implementation detects an
attempt to free invalid pointer (attachment: malloc_check_3.txt)

I can also reproduce this with 1.9.2-p290 and 1.9.3-p0 as well as
latest trunk, so it has been around a while and a fix needs to be
backported.


Files

gdb_bt.txt (2.57 KB) gdb_bt.txt GDB backtrace normalperson (Eric Wong), 12/03/2011 10:37 AM
malloc_check_3.txt (6.12 KB) malloc_check_3.txt output with MALLOC_CHECK_=3 when run with GNU libc normalperson (Eric Wong), 12/03/2011 10:37 AM
fiber_fork.rb (54 Bytes) fiber_fork.rb script to reproduce error normalperson (Eric Wong), 12/03/2011 10:37 AM
bug5700.patch (2.06 KB) bug5700.patch nagachika (Tomoyuki Chikanaga), 02/10/2012 12:30 PM

Added by naruse (Yui NARUSE) almost 13 years ago

Ruby master - Revision 8cdf5c41

merge revision(s) 34629,34630:

    * cont.c (rb_fiber_reset_root_local_storage): add a new function to
      restore rb_thread_t::local_storage.

    * cont.c (rb_obj_is_fiber): add a new function to tell finalizer to
      prevent fibers from destroy.

    * gc.c (rb_objspace_call_finalizer): don't sweep fibers at finalizing
      objspace.

    * internal.h (rb_fiber_reset_root_local_storage, rb_obj_is_fiber):
      add prototypes.

    * vm.c (ruby_vm_destruct): reset main thread's local_storage before
      free main thread. rb_thread_t::local_storage is replaced by fiber's
      local storage when forked from fiber, and it should be already freed
      when the fiber was destroyed.

    * test/ruby/test_fiber.rb (test_fork_from_fiber): add test for fork
      from fiber.
      when the fiber was destroyed. [ruby-core:41456] [Bug #5700]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_3@34637 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

ActionsLike0

Also available in: Atom PDF