ruby-changes:52380
From: normal <ko1@a...>
Date: Wed, 29 Aug 2018 17:04:15 +0900 (JST)
Subject: [ruby-changes:52380] normal:r64589 (trunk): cont.c: set th->root_fiber to current fiber at fork
normal 2018-08-29 17:04:09 +0900 (Wed, 29 Aug 2018) New Revision: 64589 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=64589 Log: cont.c: set th->root_fiber to current fiber at fork Otherwise, th->root_fiber can point to an invalid Fiber, because Fibers do not live across fork. So consider whatever Fiber is running the root fiber. [ruby-core:88723] [Bug #15041] Modified files: trunk/cont.c trunk/test/ruby/test_fiber.rb trunk/thread.c Index: thread.c =================================================================== --- thread.c (revision 64588) +++ thread.c (revision 64589) @@ -4381,6 +4381,7 @@ terminate_atfork_i(rb_thread_t *th, cons https://github.com/ruby/ruby/blob/trunk/thread.c#L4381 /* mjit.c */ void mjit_child_after_fork(void); +void rb_fiber_atfork(rb_thread_t *); void rb_thread_atfork(void) { @@ -4388,6 +4389,7 @@ rb_thread_atfork(void) https://github.com/ruby/ruby/blob/trunk/thread.c#L4389 rb_thread_atfork_internal(th, terminate_atfork_i); th->join_list = NULL; rb_mutex_cleanup_keeping_mutexes(th); + rb_fiber_atfork(th); /* We don't want reproduce CVE-2003-0900. */ rb_reset_random_seed(); Index: cont.c =================================================================== --- cont.c (revision 64588) +++ cont.c (revision 64589) @@ -1977,6 +1977,18 @@ fiber_to_s(VALUE fibval) https://github.com/ruby/ruby/blob/trunk/cont.c#L1977 return rb_block_to_s(fibval, &proc->block, status_info); } +#ifdef HAVE_WORKING_FORK +void +rb_fiber_atfork(rb_thread_t *th) +{ + if (&th->root_fiber->cont.saved_ec != th->ec) { + th->root_fiber = th->ec->fiber_ptr; + th->root_fiber->cont.type = ROOT_FIBER_CONTEXT; + } + th->root_fiber->prev = 0; +} +#endif + /* * Document-class: FiberError * Index: test/ruby/test_fiber.rb =================================================================== --- test/ruby/test_fiber.rb (revision 64588) +++ test/ruby/test_fiber.rb (revision 64589) @@ -269,7 +269,11 @@ class TestFiber < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_fiber.rb#L269 end bug5700 = '[ruby-core:41456]' assert_nothing_raised(bug5700) do - Fiber.new{ pid = fork {} }.resume + Fiber.new do + pid = fork do + Fiber.new {}.transfer + end + end.resume end pid, status = Process.waitpid2(pid) assert_equal(0, status.exitstatus, bug5700) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/