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

ruby-changes:49069

From: eregon <ko1@a...>
Date: Wed, 13 Dec 2017 03:44:00 +0900 (JST)
Subject: [ruby-changes:49069] eregon:r61184 (trunk): Avoid creating a Thread for shutting down a DRbServer

eregon	2017-12-13 03:43:55 +0900 (Wed, 13 Dec 2017)

  New Revision: 61184

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

  Log:
    Avoid creating a Thread for shutting down a DRbServer
    
    * lib/drb/drb.rb: avoid creating a Thread and call the shutdown logic
      directly. Do not try to kill or join the current Thread.
      Thread.new { stop_service } caused "can't alloc thread (ThreadError)",
      which is shown with Thread.report_on_exception = true.
      [Bug #14171]

  Modified files:
    trunk/lib/drb/drb.rb
Index: lib/drb/drb.rb
===================================================================
--- lib/drb/drb.rb	(revision 61183)
+++ lib/drb/drb.rb	(revision 61184)
@@ -1466,12 +1466,7 @@ module DRb https://github.com/ruby/ruby/blob/trunk/lib/drb/drb.rb#L1466
       if  Thread.current['DRb'] && Thread.current['DRb']['server'] == self
         Thread.current['DRb']['stop_service'] = true
       else
-        if @protocol.respond_to? :shutdown
-          @protocol.shutdown
-        else
-          [@thread, *@grp.list].each {|thread| thread.kill} # xxx: Thread#kill
-        end
-        @thread.join
+        shutdown
       end
     end
 
@@ -1490,6 +1485,18 @@ module DRb https://github.com/ruby/ruby/blob/trunk/lib/drb/drb.rb#L1485
 
     private
 
+    def shutdown
+      current = Thread.current
+      if @protocol.respond_to? :shutdown
+        @protocol.shutdown
+      else
+        [@thread, *@grp.list].each { |thread|
+          thread.kill unless thread == current # xxx: Thread#kill
+        }
+      end
+      @thread.join unless @thread == current
+    end
+
     ##
     # Starts the DRb main loop in a new thread.
 
@@ -1671,9 +1678,7 @@ module DRb https://github.com/ruby/ruby/blob/trunk/lib/drb/drb.rb#L1678
             error_print(e) if verbose
           ensure
             client.close unless succ
-            if Thread.current['DRb']['stop_service']
-              Thread.new { stop_service }
-            end
+            shutdown if Thread.current['DRb']['stop_service']
             break unless succ
           end
         end

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

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