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

ruby-changes:51848

From: normal <ko1@a...>
Date: Thu, 26 Jul 2018 17:30:15 +0900 (JST)
Subject: [ruby-changes:51848] normal:r64062 (trunk): cont.c (ec_switch): prevent delayed/missed trap interrupt race

normal	2018-07-26 17:30:10 +0900 (Thu, 26 Jul 2018)

  New Revision: 64062

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

  Log:
    cont.c (ec_switch): prevent delayed/missed trap interrupt race
    
    timer-thread may set trap interrupt with rb_threadptr_check_signal
    at any time independent of GVL.  This means timer-thread may set
    the trap interrupt flag on the previous execution context; causing
    the flag to be unnoticed until a future ec switch (or lost
    completely if the ec is done).
    
    Note: I avoid relying on th->interrupt_lock here and use
    atomics because we won't be able to rely on it for proposed lazy
    timer-thread [Misc #14937].
    
    This regression affects Ruby 2.5 as it was introduced by moving
    interrupt_flag to `ec' which is an unstable pointer.  Ruby <= 2.4
    was unaffected because vm->main_thread->interrupt_flag never
    changed.
    
    [ruby-core:88119] [Bug #14939]

  Modified files:
    trunk/cont.c
Index: cont.c
===================================================================
--- cont.c	(revision 64061)
+++ cont.c	(revision 64062)
@@ -262,7 +262,17 @@ static inline void https://github.com/ruby/ruby/blob/trunk/cont.c#L262
 ec_switch(rb_thread_t *th, rb_fiber_t *fib)
 {
     rb_execution_context_t *ec = &fib->cont.saved_ec;
+
     ruby_current_execution_context_ptr = th->ec = ec;
+
+    /*
+     * timer-thread may set trap interrupt on previous th->ec at any time;
+     * ensure we do not delay (or lose) the trap interrupt handling.
+     */
+    if (th->vm->main_thread == th && rb_signal_buff_size() > 0) {
+        RUBY_VM_SET_TRAP_INTERRUPT(ec);
+    }
+
     VM_ASSERT(ec->fiber_ptr->cont.self == 0 || ec->vm_stack != NULL);
 }
 

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

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