[前][次][番号順一覧][スレッド一覧]

ruby-changes:41301

From: normal <ko1@a...>
Date: Wed, 30 Dec 2015 03:20:36 +0900 (JST)
Subject: [ruby-changes:41301] normal:r53373 (trunk): thread_pthread.c (rb_thread_create_timer_thread): fix race

normal	2015-12-30 03:20:27 +0900 (Wed, 30 Dec 2015)

  New Revision: 53373

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=53373

  Log:
    thread_pthread.c (rb_thread_create_timer_thread): fix race
    
    This fixes an occasional [ASYNC BUG] failure in
    bootstraptest/test_fork.rb '[ruby-dev:37934]'
    which tests fork/pthread_create failure by setting
    RLIMIT_NPROC to 1 and triggering EAGAIN on pthread_create
    when attempting to recreate the timer thread.
    
    The problem timeline is as follows:
    
    thread 1                           thread 2
    ---------------------------------------------------------------
    rb_thread_create_timer_thread
    setup_communication_pipe
                                       rb_thread_wakeup_timer_thread_low
    pthread_create fails               pipe looks valid, write!
    CLOSE_INVALIDATE (x4)              EBADF -> ASYNC BUG
    
    The checks in rb_thread_wakeup_timer_thread_low only tried to
    guarantee proper ordering with native_stop_timer_thread, not
    rb_thread_create_timer_thread :x
    
    Now, this should allow rb_thread_create_timer_thread to
    synchronize properly with rb_thread_wakeup_timer_thread_low by
    delaying the validation marking of the timer_thread_pipe until
    we are certain the timer thread is alive.
    
    In this version, rb_thread_wakeup_timer_thread_low becomes a
    noop.  Threading is still completely broken with NPROC==1, but
    there's not much we can do about it beside warn the user.
    We no longer spew a scary [ASYNC BUG] message or dump core
    on them.
    
    * thread_pthread.c (setup_communication_pipe): delay setting owner
      (rb_thread_create_timer_thread): until thread creation succeeds
      [ruby-core:72590] [Bug #11922]

  Modified files:
    trunk/ChangeLog
    trunk/thread_pthread.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 53372)
+++ ChangeLog	(revision 53373)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Wed Dec 30 02:55:09 2015  Eric Wong  <e@8...>
+
+	* thread_pthread.c (setup_communication_pipe): delay setting owner
+	  (rb_thread_create_timer_thread): until thread creation succeeds
+	  [ruby-core:72590] [Bug #11922]
+
 Tue Dec 29 19:12:46 2015  Nobuyoshi Nakada  <nobu@r...>
 
 	* ruby.c (proc_options): -W command line option should be able to
Index: thread_pthread.c
===================================================================
--- thread_pthread.c	(revision 53372)
+++ thread_pthread.c	(revision 53373)
@@ -1406,8 +1406,6 @@ setup_communication_pipe(void) https://github.com/ruby/ruby/blob/trunk/thread_pthread.c#L1406
 	return e;
     }
 
-    /* validate pipe on this process */
-    timer_thread_pipe.owner_process = getpid();
     return 0;
 }
 
@@ -1615,6 +1613,9 @@ rb_thread_create_timer_thread(void) https://github.com/ruby/ruby/blob/trunk/thread_pthread.c#L1613
 #endif
 	    return;
 	}
+
+	/* validate pipe on this process */
+	timer_thread_pipe.owner_process = getpid();
 	timer_thread.created = 1;
 #ifdef HAVE_PTHREAD_ATTR_INIT
 	pthread_attr_destroy(&attr);

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]