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

ruby-changes:41367

From: nobu <ko1@a...>
Date: Tue, 5 Jan 2016 15:09:10 +0900 (JST)
Subject: [ruby-changes:41367] nobu:r53439 (trunk): leakchecker.rb: remove temporary measure

nobu	2016-01-05 15:09:17 +0900 (Tue, 05 Jan 2016)

  New Revision: 53439

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

  Log:
    leakchecker.rb: remove temporary measure
    
    * lib/webrick/utils.rb (WEBrick::Utils::TimeoutHandler#watcher):
      make watcher thread restartable.
    
    * lib/webrick/utils.rb (WEBrick::Utils::TimeoutHandler#terminate):
      new method to terminate watcher thread.
    
    * test/lib/leakchecker.rb (LeakChecker#find_threads): revert
      r46941.

  Modified files:
    trunk/lib/webrick/utils.rb
    trunk/test/lib/leakchecker.rb
    trunk/test/net/http/utils.rb
    trunk/test/open-uri/test_open-uri.rb
    trunk/test/open-uri/test_ssl.rb
    trunk/test/rubygems/test_gem_remote_fetcher.rb
    trunk/test/webrick/test_cgi.rb
    trunk/test/webrick/test_filehandler.rb
    trunk/test/webrick/test_httpauth.rb
    trunk/test/webrick/test_httpproxy.rb
    trunk/test/webrick/test_httprequest.rb
    trunk/test/webrick/test_httpserver.rb
    trunk/test/webrick/test_utils.rb
    trunk/test/xmlrpc/webrick_testing.rb
Index: lib/webrick/utils.rb
===================================================================
--- lib/webrick/utils.rb	(revision 53438)
+++ lib/webrick/utils.rb	(revision 53439)
@@ -124,8 +124,6 @@ module WEBrick https://github.com/ruby/ruby/blob/trunk/lib/webrick/utils.rb#L124
     class TimeoutHandler
       include Singleton
 
-      class Thread < ::Thread; end
-
       ##
       # Mutex used to synchronize access across threads
       TimeoutMutex = Mutex.new # :nodoc:
@@ -145,6 +143,10 @@ module WEBrick https://github.com/ruby/ruby/blob/trunk/lib/webrick/utils.rb#L143
         instance.cancel(Thread.current, id)
       end
 
+      def self.terminate
+        instance.terminate
+      end
+
       ##
       # Creates a new TimeoutHandler.  You should use ::register and ::cancel
       # instead of creating the timeout handler directly.
@@ -153,7 +155,12 @@ module WEBrick https://github.com/ruby/ruby/blob/trunk/lib/webrick/utils.rb#L155
           @timeout_info = Hash.new
         }
         @queue = Queue.new
-        @watcher = Thread.start{
+        @watcher = nil
+      end
+
+      # :nodoc:
+      private \
+        def watch
           to_interrupt = []
           while true
             now = Time.now
@@ -184,8 +191,17 @@ module WEBrick https://github.com/ruby/ruby/blob/trunk/lib/webrick/utils.rb#L191
             end
             @queue.clear
           end
-        }
-      end
+        end
+
+      # :nodoc:
+      private \
+        def watcher
+          (w = @watcher)&.alive? and return w # usual case
+          TimeoutMutex.synchronize{
+            (w = @watcher)&.alive? and next w # pathological check
+            @watcher = Thread.start(&method(:watch))
+          }
+        end
 
       ##
       # Interrupts the timeout handler +id+ and raises +exception+
@@ -203,10 +219,10 @@ module WEBrick https://github.com/ruby/ruby/blob/trunk/lib/webrick/utils.rb#L219
       def register(thread, time, exception)
         info = nil
         TimeoutMutex.synchronize{
-          @timeout_info[thread] ||= Array.new
-          @timeout_info[thread] << (info = [time, exception])
+          (@timeout_info[thread] ||= []) << (info = [time, exception])
         }
         @queue.push nil
+        watcher
         return info.object_id
       end
 
@@ -224,6 +240,14 @@ module WEBrick https://github.com/ruby/ruby/blob/trunk/lib/webrick/utils.rb#L240
           return false
         }
       end
+
+      ##
+      def terminate
+        TimeoutMutex.synchronize{
+          @timeout_info.clear
+          @watcher&.kill&.join
+        }
+      end
     end
 
     ##
Index: test/open-uri/test_ssl.rb
===================================================================
--- test/open-uri/test_ssl.rb	(revision 53438)
+++ test/open-uri/test_ssl.rb	(revision 53439)
@@ -52,6 +52,8 @@ class TestOpenURISSL https://github.com/ruby/ruby/blob/trunk/test/open-uri/test_ssl.rb#L52
       }
       assert_join_threads(threads)
     }
+  ensure
+    WEBrick::Utils::TimeoutHandler.terminate
   end
 
   def setup
Index: test/open-uri/test_open-uri.rb
===================================================================
--- test/open-uri/test_open-uri.rb	(revision 53438)
+++ test/open-uri/test_open-uri.rb	(revision 53439)
@@ -43,6 +43,8 @@ class TestOpenURI < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/open-uri/test_open-uri.rb#L43
       }
       assert_join_threads([client_thread, server_thread2])
     }
+  ensure
+    WEBrick::Utils::TimeoutHandler.terminate
   end
 
   def with_env(h)
Index: test/webrick/test_httprequest.rb
===================================================================
--- test/webrick/test_httprequest.rb	(revision 53438)
+++ test/webrick/test_httprequest.rb	(revision 53439)
@@ -4,6 +4,11 @@ require "stringio" https://github.com/ruby/ruby/blob/trunk/test/webrick/test_httprequest.rb#L4
 require "test/unit"
 
 class TestWEBrickHTTPRequest < Test::Unit::TestCase
+  def teardown
+    WEBrick::Utils::TimeoutHandler.terminate
+    super
+  end
+
   def test_simple_request
     msg = <<-_end_of_message_
 GET /
Index: test/webrick/test_utils.rb
===================================================================
--- test/webrick/test_utils.rb	(revision 53438)
+++ test/webrick/test_utils.rb	(revision 53439)
@@ -3,6 +3,11 @@ require "test/unit" https://github.com/ruby/ruby/blob/trunk/test/webrick/test_utils.rb#L3
 require "webrick/utils"
 
 class TestWEBrickUtils < Test::Unit::TestCase
+  def teardown
+    WEBrick::Utils::TimeoutHandler.terminate
+    super
+  end
+
   def assert_expired(m)
     Thread.handle_interrupt(Timeout::Error => :never, EX => :never) do
       assert_empty(m::TimeoutHandler.instance.instance_variable_get(:@timeout_info))
Index: test/webrick/test_httpauth.rb
===================================================================
--- test/webrick/test_httpauth.rb	(revision 53438)
+++ test/webrick/test_httpauth.rb	(revision 53439)
@@ -7,6 +7,11 @@ require "webrick/httpauth/basicauth" https://github.com/ruby/ruby/blob/trunk/test/webrick/test_httpauth.rb#L7
 require_relative "utils"
 
 class TestWEBrickHTTPAuth < Test::Unit::TestCase
+  def teardown
+    WEBrick::Utils::TimeoutHandler.terminate
+    super
+  end
+
   def test_basic_auth
     log_tester = lambda {|log, access_log|
       assert_equal(1, log.length)
Index: test/webrick/test_cgi.rb
===================================================================
--- test/webrick/test_cgi.rb	(revision 53438)
+++ test/webrick/test_cgi.rb	(revision 53439)
@@ -7,6 +7,11 @@ require "test/unit" https://github.com/ruby/ruby/blob/trunk/test/webrick/test_cgi.rb#L7
 class TestWEBrickCGI < Test::Unit::TestCase
   CRLF = "\r\n"
 
+  def teardown
+    WEBrick::Utils::TimeoutHandler.terminate
+    super
+  end
+
   def start_cgi_server(log_tester=TestWEBrick::DefaultLogTester, &block)
     config = {
       :CGIInterpreter => TestWEBrick::RubyBin,
Index: test/webrick/test_httpserver.rb
===================================================================
--- test/webrick/test_httpserver.rb	(revision 53438)
+++ test/webrick/test_httpserver.rb	(revision 53439)
@@ -12,6 +12,11 @@ class TestWEBrickHTTPServer < Test::Unit https://github.com/ruby/ruby/blob/trunk/test/webrick/test_httpserver.rb#L12
   end
   NoLog = WEBrick::Log.new(empty_log, WEBrick::BasicLog::WARN)
 
+  def teardown
+    WEBrick::Utils::TimeoutHandler.terminate
+    super
+  end
+
   def test_mount
     httpd = WEBrick::HTTPServer.new(
       :Logger => NoLog,
Index: test/webrick/test_filehandler.rb
===================================================================
--- test/webrick/test_filehandler.rb	(revision 53438)
+++ test/webrick/test_filehandler.rb	(revision 53439)
@@ -5,6 +5,11 @@ require "webrick" https://github.com/ruby/ruby/blob/trunk/test/webrick/test_filehandler.rb#L5
 require "stringio"
 
 class WEBrick::TestFileHandler < Test::Unit::TestCase
+  def teardown
+    WEBrick::Utils::TimeoutHandler.terminate
+    super
+  end
+
   def default_file_handler(filename)
     klass = WEBrick::HTTPServlet::DefaultFileHandler
     klass.new(WEBrick::Config::HTTP, filename)
Index: test/webrick/test_httpproxy.rb
===================================================================
--- test/webrick/test_httpproxy.rb	(revision 53438)
+++ test/webrick/test_httpproxy.rb	(revision 53439)
@@ -13,6 +13,11 @@ end https://github.com/ruby/ruby/blob/trunk/test/webrick/test_httpproxy.rb#L13
 require File.expand_path("utils.rb", File.dirname(__FILE__))
 
 class TestWEBrickHTTPProxy < Test::Unit::TestCase
+  def teardown
+    WEBrick::Utils::TimeoutHandler.terminate
+    super
+  end
+
   def test_fake_proxy
     assert_nil(WEBrick::FakeProxyURI.scheme)
     assert_nil(WEBrick::FakeProxyURI.host)
Index: test/xmlrpc/webrick_testing.rb
===================================================================
--- test/xmlrpc/webrick_testing.rb	(revision 53438)
+++ test/xmlrpc/webrick_testing.rb	(revision 53439)
@@ -3,6 +3,11 @@ require 'timeout' https://github.com/ruby/ruby/blob/trunk/test/xmlrpc/webrick_testing.rb#L3
 
 module TestXMLRPC
 module WEBrick_Testing
+  def teardown
+    WEBrick::Utils::TimeoutHandler.terminate
+    super
+  end
+
   def start_server(logger, config={})
     raise "already started" if defined?(@__server) && @__server
     @__started = false
Index: test/lib/leakchecker.rb
===================================================================
--- test/lib/leakchecker.rb	(revision 53438)
+++ test/lib/leakchecker.rb	(revision 53439)
@@ -139,7 +139,7 @@ class LeakChecker https://github.com/ruby/ruby/blob/trunk/test/lib/leakchecker.rb#L139
 
   def find_threads
     Thread.list.find_all {|t|
-      t != Thread.current && /\AWEBrick::/ !~ t.class.name && t.alive?
+      t != Thread.current && t.alive?
     }
   end
 
Index: test/net/http/utils.rb
===================================================================
--- test/net/http/utils.rb	(revision 53438)
+++ test/net/http/utils.rb	(revision 53439)
@@ -36,6 +36,7 @@ module TestNetHTTPUtils https://github.com/ruby/ruby/blob/trunk/test/net/http/utils.rb#L36
     if @server
       @server.shutdown
       @server_thread.join
+      WEBrick::Utils::TimeoutHandler.terminate
     end
     @log_tester.call(@log) if @log_tester
     # resume global state
Index: test/rubygems/test_gem_remote_fetcher.rb
===================================================================
--- test/rubygems/test_gem_remote_fetcher.rb	(revision 53438)
+++ test/rubygems/test_gem_remote_fetcher.rb	(revision 53439)
@@ -924,6 +924,7 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg== https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem_remote_fetcher.rb#L924
         @ssl_server_thread.kill.join
         @ssl_server_thread = nil
       end
+      WEBrick::Utils::TimeoutHandler.terminate
     end
 
     def normal_server_port

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

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