ruby-changes:50686
From: naruse <ko1@a...>
Date: Tue, 20 Mar 2018 11:08:36 +0900 (JST)
Subject: [ruby-changes:50686] naruse:r62852 (ruby_2_5): merge revision(s) 62668: [Backport #14578]
naruse 2018-03-20 11:08:27 +0900 (Tue, 20 Mar 2018) New Revision: 62852 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=62852 Log: merge revision(s) 62668: [Backport #14578] thread.c: reset waitq of keeping mutexes in child We must not maintain references to threads in the parent process in any mutexes held by the child process. * thread_sync.c (rb_mutex_cleanup_keeping_mutexes): new function * thread.c (rb_thread_atfork): cleanup keeping mutexes [ruby-core:85940] [Bug #14578] Fixes: r58604 (commit 3586c9e0876e784767a1c1adba9ebc2499fa0ec2) ("reduce rb_mutex_t size from 160 to 80 bytes on 64-bit") Modified directories: branches/ruby_2_5/ Modified files: branches/ruby_2_5/test/ruby/test_thread.rb branches/ruby_2_5/thread.c branches/ruby_2_5/thread_sync.c branches/ruby_2_5/version.h Index: ruby_2_5/version.h =================================================================== --- ruby_2_5/version.h (revision 62851) +++ ruby_2_5/version.h (revision 62852) @@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_5/version.h#L1 #define RUBY_VERSION "2.5.0" #define RUBY_RELEASE_DATE "2018-03-19" -#define RUBY_PATCHLEVEL 42 +#define RUBY_PATCHLEVEL 43 #define RUBY_RELEASE_YEAR 2018 #define RUBY_RELEASE_MONTH 3 Index: ruby_2_5/thread.c =================================================================== --- ruby_2_5/thread.c (revision 62851) +++ ruby_2_5/thread.c (revision 62852) @@ -4208,6 +4208,7 @@ rb_thread_atfork(void) https://github.com/ruby/ruby/blob/trunk/ruby_2_5/thread.c#L4208 rb_thread_t *th = GET_THREAD(); rb_thread_atfork_internal(th, terminate_atfork_i); th->join_list = NULL; + rb_mutex_cleanup_keeping_mutexes(th); /* We don't want reproduce CVE-2003-0900. */ rb_reset_random_seed(); Index: ruby_2_5/thread_sync.c =================================================================== --- ruby_2_5/thread_sync.c (revision 62851) +++ ruby_2_5/thread_sync.c (revision 62852) @@ -415,6 +415,20 @@ rb_mutex_abandon_all(rb_mutex_t *mutexes https://github.com/ruby/ruby/blob/trunk/ruby_2_5/thread_sync.c#L415 list_head_init(&mutex->waitq); } } + +/* + * All other threads are dead in the a new child process, so waitqs + * contain references to dead threads which we need to clean up + */ +static void +rb_mutex_cleanup_keeping_mutexes(const rb_thread_t *current_thread) +{ + rb_mutex_t *mutex = current_thread->keeping_mutexes; + while (mutex) { + list_head_init(&mutex->waitq); + mutex = mutex->next_mutex; + } +} #endif static VALUE Index: ruby_2_5/test/ruby/test_thread.rb =================================================================== --- ruby_2_5/test/ruby/test_thread.rb (revision 62851) +++ ruby_2_5/test/ruby/test_thread.rb (revision 62852) @@ -1188,6 +1188,17 @@ q.pop https://github.com/ruby/ruby/blob/trunk/ruby_2_5/test/ruby/test_thread.rb#L1188 assert_predicate(status, :success?, bug9751) end if Process.respond_to?(:fork) + def test_fork_while_locked + m = Mutex.new + thrs = [] + 3.times do |i| + thrs << Thread.new { m.synchronize { Process.waitpid2(fork{})[1] } } + end + thrs.each do |t| + assert_predicate t.value, :success?, '[ruby-core:85940] [Bug #14578]' + end + end if Process.respond_to?(:fork) + def test_subclass_no_initialize t = Module.new do break eval("class C\u{30b9 30ec 30c3 30c9} < Thread; self; end") Index: ruby_2_5 =================================================================== --- ruby_2_5 (revision 62851) +++ ruby_2_5 (revision 62852) Property changes on: ruby_2_5 ___________________________________________________________________ Modified: svn:mergeinfo ## -0,0 +0,1 ## Merged /trunk:r62668 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/