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

ruby-changes:47106

From: usa <ko1@a...>
Date: Fri, 30 Jun 2017 19:56:39 +0900 (JST)
Subject: [ruby-changes:47106] usa:r59221 (ruby_2_3): merge revision(s) 58696: [Backport #11384]

usa	2017-06-30 19:56:33 +0900 (Fri, 30 Jun 2017)

  New Revision: 59221

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

  Log:
    merge revision(s) 58696: [Backport #11384]
    
    autoload: always wait on loading thread
    
    We cannot assume autoload_provided/rb_feature_provided returning
    TRUE means it is safe to proceed without waiting.  Another
    thread may call rb_provide_feature before setting the constant
    (via autoload_const_set).  So we must wait until autoload is
    completed by another thread.
    
    Note: this patch was tested with an explicit rb_thread_schedule
    in rb_provide_feature to make the race condition more apparent
    as suggested by <s.wanabe@g...>:
    > --- a/load.c
    > +++ b/load.c
    > @@ -563,6 +563,7 @@ rb_provide_feature(VALUE feature)
    >      rb_str_freeze(feature);
    >
    >      rb_ary_push(features, rb_fstring(feature));
    > +rb_thread_schedule();
    >      features_index_add(feature, INT2FIX(RARRAY_LEN(features)-1));
    >      reset_loaded_features_snapshot();
    >  }
    
    * variable.c (check_autoload_required): do not assume a provided
      feature means autoload is complete, always wait if autoload is
      being performed by another thread.
      [ruby-core:81105] [Bug #11384] Thanks to <s.wanabe@g...>

  Modified directories:
    branches/ruby_2_3/
  Modified files:
    branches/ruby_2_3/ChangeLog
    branches/ruby_2_3/variable.c
    branches/ruby_2_3/version.h
Index: ruby_2_3/version.h
===================================================================
--- ruby_2_3/version.h	(revision 59220)
+++ ruby_2_3/version.h	(revision 59221)
@@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_3/version.h#L1
 #define RUBY_VERSION "2.3.5"
 #define RUBY_RELEASE_DATE "2017-06-30"
-#define RUBY_PATCHLEVEL 317
+#define RUBY_PATCHLEVEL 318
 
 #define RUBY_RELEASE_YEAR 2017
 #define RUBY_RELEASE_MONTH 6
Index: ruby_2_3/variable.c
===================================================================
--- ruby_2_3/variable.c	(revision 59220)
+++ ruby_2_3/variable.c	(revision 59221)
@@ -2020,6 +2020,17 @@ check_autoload_required(VALUE mod, ID id https://github.com/ruby/ruby/blob/trunk/ruby_2_3/variable.c#L2020
     if (!RSTRING_PTR(file) || !*RSTRING_PTR(file)) {
 	rb_raise(rb_eArgError, "empty file name");
     }
+
+    /*
+     * if somebody else is autoloading, we MUST wait for them, since
+     * rb_provide_feature can provide a feature before autoload_const_set
+     * completes.  We must wait until autoload_const_set finishes in
+     * the other thread.
+     */
+    if (ele->state && ele->state->thread != rb_thread_current()) {
+	return load;
+    }
+
     loading = RSTRING_PTR(file);
     safe = rb_safe_level();
     rb_set_safe_level_force(0);
Index: ruby_2_3/ChangeLog
===================================================================
--- ruby_2_3/ChangeLog	(revision 59220)
+++ ruby_2_3/ChangeLog	(revision 59221)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_3/ChangeLog#L1
+Fri Jun 30 19:56:06 2017  Eric Wong  <e@8...>
+
+	* variable.c (check_autoload_required): do not assume a provided feature
+	  means autoload is complete, always wait if autoload is being performed
+	  by another thread. [Bug #11384] Thanks to s.wanabe@g...
+
 Fri Jun 30 19:53:30 2017  Nobuyoshi Nakada  <nobu@r...>
 
 	* process.c (obj2uid, obj2gid): use temporary string as the buffer
Index: ruby_2_3
===================================================================
--- ruby_2_3	(revision 59220)
+++ ruby_2_3	(revision 59221)

Property changes on: ruby_2_3
___________________________________________________________________
Modified: svn:mergeinfo
## -0,0 +0,1 ##
   Merged /trunk:r58696

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

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