Skip to content

Commit

Permalink
merge revision(s) 64589,64593: [Backport #15041]
Browse files Browse the repository at this point in the history
	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]

	cont.c (rb_fiber_atfork): th->root_fiber may not exist

	Otherwise, bootstraptest/test_fork.rb fails with -DVM_CHECK_MODE=2

	[Bug #15041]

	Fixes: r64589 "cont.c: set th->root_fiber to current fiber at fork"

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_5@66818 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
nagachika committed Jan 14, 2019
1 parent 06c9877 commit b9f11b1
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
14 changes: 14 additions & 0 deletions cont.c
Expand Up @@ -1932,6 +1932,20 @@ fiber_to_s(VALUE fibval)
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) {
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
*
Expand Down
6 changes: 5 additions & 1 deletion test/ruby/test_fiber.rb
Expand Up @@ -269,7 +269,11 @@ def test_fork_from_fiber
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)
Expand Down
2 changes: 2 additions & 0 deletions thread.c
Expand Up @@ -4231,13 +4231,15 @@ terminate_atfork_i(rb_thread_t *th, const rb_thread_t *current_th)
}
}

void rb_fiber_atfork(rb_thread_t *);
void
rb_thread_atfork(void)
{
rb_thread_t *th = GET_THREAD();
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();
Expand Down
6 changes: 3 additions & 3 deletions version.h
@@ -1,10 +1,10 @@
#define RUBY_VERSION "2.5.4"
#define RUBY_RELEASE_DATE "2019-01-11"
#define RUBY_PATCHLEVEL 128
#define RUBY_RELEASE_DATE "2019-01-14"
#define RUBY_PATCHLEVEL 129

#define RUBY_RELEASE_YEAR 2019
#define RUBY_RELEASE_MONTH 1
#define RUBY_RELEASE_DAY 11
#define RUBY_RELEASE_DAY 14

#include "ruby/version.h"

Expand Down

0 comments on commit b9f11b1

Please sign in to comment.