mirror of
				https://github.com/ruby/ruby.git
				synced 2022-11-09 12:17:21 -05:00 
			
		
		
		
	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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53439 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
		
							parent
							
								
									b01c28eeb3
								
							
						
					
					
						commit
						8d66627161
					
				
					 14 changed files with 78 additions and 8 deletions
				
			
		| 
						 | 
					@ -124,8 +124,6 @@ module WEBrick
 | 
				
			||||||
    class TimeoutHandler
 | 
					    class TimeoutHandler
 | 
				
			||||||
      include Singleton
 | 
					      include Singleton
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      class Thread < ::Thread; end
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      ##
 | 
					      ##
 | 
				
			||||||
      # Mutex used to synchronize access across threads
 | 
					      # Mutex used to synchronize access across threads
 | 
				
			||||||
      TimeoutMutex = Mutex.new # :nodoc:
 | 
					      TimeoutMutex = Mutex.new # :nodoc:
 | 
				
			||||||
| 
						 | 
					@ -145,6 +143,10 @@ module WEBrick
 | 
				
			||||||
        instance.cancel(Thread.current, id)
 | 
					        instance.cancel(Thread.current, id)
 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      def self.terminate
 | 
				
			||||||
 | 
					        instance.terminate
 | 
				
			||||||
 | 
					      end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      ##
 | 
					      ##
 | 
				
			||||||
      # Creates a new TimeoutHandler.  You should use ::register and ::cancel
 | 
					      # Creates a new TimeoutHandler.  You should use ::register and ::cancel
 | 
				
			||||||
      # instead of creating the timeout handler directly.
 | 
					      # instead of creating the timeout handler directly.
 | 
				
			||||||
| 
						 | 
					@ -153,7 +155,12 @@ module WEBrick
 | 
				
			||||||
          @timeout_info = Hash.new
 | 
					          @timeout_info = Hash.new
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        @queue = Queue.new
 | 
					        @queue = Queue.new
 | 
				
			||||||
        @watcher = Thread.start{
 | 
					        @watcher = nil
 | 
				
			||||||
 | 
					      end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      # :nodoc:
 | 
				
			||||||
 | 
					      private \
 | 
				
			||||||
 | 
					        def watch
 | 
				
			||||||
          to_interrupt = []
 | 
					          to_interrupt = []
 | 
				
			||||||
          while true
 | 
					          while true
 | 
				
			||||||
            now = Time.now
 | 
					            now = Time.now
 | 
				
			||||||
| 
						 | 
					@ -184,8 +191,17 @@ module WEBrick
 | 
				
			||||||
            end
 | 
					            end
 | 
				
			||||||
            @queue.clear
 | 
					            @queue.clear
 | 
				
			||||||
          end
 | 
					          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+
 | 
					      # Interrupts the timeout handler +id+ and raises +exception+
 | 
				
			||||||
| 
						 | 
					@ -203,10 +219,10 @@ module WEBrick
 | 
				
			||||||
      def register(thread, time, exception)
 | 
					      def register(thread, time, exception)
 | 
				
			||||||
        info = nil
 | 
					        info = nil
 | 
				
			||||||
        TimeoutMutex.synchronize{
 | 
					        TimeoutMutex.synchronize{
 | 
				
			||||||
          @timeout_info[thread] ||= Array.new
 | 
					          (@timeout_info[thread] ||= []) << (info = [time, exception])
 | 
				
			||||||
          @timeout_info[thread] << (info = [time, exception])
 | 
					 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        @queue.push nil
 | 
					        @queue.push nil
 | 
				
			||||||
 | 
					        watcher
 | 
				
			||||||
        return info.object_id
 | 
					        return info.object_id
 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -224,6 +240,14 @@ module WEBrick
 | 
				
			||||||
          return false
 | 
					          return false
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      ##
 | 
				
			||||||
 | 
					      def terminate
 | 
				
			||||||
 | 
					        TimeoutMutex.synchronize{
 | 
				
			||||||
 | 
					          @timeout_info.clear
 | 
				
			||||||
 | 
					          @watcher&.kill&.join
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					      end
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ##
 | 
					    ##
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -139,7 +139,7 @@ class LeakChecker
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  def find_threads
 | 
					  def find_threads
 | 
				
			||||||
    Thread.list.find_all {|t|
 | 
					    Thread.list.find_all {|t|
 | 
				
			||||||
      t != Thread.current && /\AWEBrick::/ !~ t.class.name && t.alive?
 | 
					      t != Thread.current && t.alive?
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -36,6 +36,7 @@ module TestNetHTTPUtils
 | 
				
			||||||
    if @server
 | 
					    if @server
 | 
				
			||||||
      @server.shutdown
 | 
					      @server.shutdown
 | 
				
			||||||
      @server_thread.join
 | 
					      @server_thread.join
 | 
				
			||||||
 | 
					      WEBrick::Utils::TimeoutHandler.terminate
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
    @log_tester.call(@log) if @log_tester
 | 
					    @log_tester.call(@log) if @log_tester
 | 
				
			||||||
    # resume global state
 | 
					    # resume global state
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -43,6 +43,8 @@ class TestOpenURI < Test::Unit::TestCase
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
      assert_join_threads([client_thread, server_thread2])
 | 
					      assert_join_threads([client_thread, server_thread2])
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					  ensure
 | 
				
			||||||
 | 
					    WEBrick::Utils::TimeoutHandler.terminate
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  def with_env(h)
 | 
					  def with_env(h)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -52,6 +52,8 @@ class TestOpenURISSL
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
      assert_join_threads(threads)
 | 
					      assert_join_threads(threads)
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					  ensure
 | 
				
			||||||
 | 
					    WEBrick::Utils::TimeoutHandler.terminate
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  def setup
 | 
					  def setup
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -924,6 +924,7 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg==
 | 
				
			||||||
        @ssl_server_thread.kill.join
 | 
					        @ssl_server_thread.kill.join
 | 
				
			||||||
        @ssl_server_thread = nil
 | 
					        @ssl_server_thread = nil
 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
 | 
					      WEBrick::Utils::TimeoutHandler.terminate
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def normal_server_port
 | 
					    def normal_server_port
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -7,6 +7,11 @@ require "test/unit"
 | 
				
			||||||
class TestWEBrickCGI < Test::Unit::TestCase
 | 
					class TestWEBrickCGI < Test::Unit::TestCase
 | 
				
			||||||
  CRLF = "\r\n"
 | 
					  CRLF = "\r\n"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  def teardown
 | 
				
			||||||
 | 
					    WEBrick::Utils::TimeoutHandler.terminate
 | 
				
			||||||
 | 
					    super
 | 
				
			||||||
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  def start_cgi_server(log_tester=TestWEBrick::DefaultLogTester, &block)
 | 
					  def start_cgi_server(log_tester=TestWEBrick::DefaultLogTester, &block)
 | 
				
			||||||
    config = {
 | 
					    config = {
 | 
				
			||||||
      :CGIInterpreter => TestWEBrick::RubyBin,
 | 
					      :CGIInterpreter => TestWEBrick::RubyBin,
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -5,6 +5,11 @@ require "webrick"
 | 
				
			||||||
require "stringio"
 | 
					require "stringio"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class WEBrick::TestFileHandler < Test::Unit::TestCase
 | 
					class WEBrick::TestFileHandler < Test::Unit::TestCase
 | 
				
			||||||
 | 
					  def teardown
 | 
				
			||||||
 | 
					    WEBrick::Utils::TimeoutHandler.terminate
 | 
				
			||||||
 | 
					    super
 | 
				
			||||||
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  def default_file_handler(filename)
 | 
					  def default_file_handler(filename)
 | 
				
			||||||
    klass = WEBrick::HTTPServlet::DefaultFileHandler
 | 
					    klass = WEBrick::HTTPServlet::DefaultFileHandler
 | 
				
			||||||
    klass.new(WEBrick::Config::HTTP, filename)
 | 
					    klass.new(WEBrick::Config::HTTP, filename)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -7,6 +7,11 @@ require "webrick/httpauth/basicauth"
 | 
				
			||||||
require_relative "utils"
 | 
					require_relative "utils"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class TestWEBrickHTTPAuth < Test::Unit::TestCase
 | 
					class TestWEBrickHTTPAuth < Test::Unit::TestCase
 | 
				
			||||||
 | 
					  def teardown
 | 
				
			||||||
 | 
					    WEBrick::Utils::TimeoutHandler.terminate
 | 
				
			||||||
 | 
					    super
 | 
				
			||||||
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  def test_basic_auth
 | 
					  def test_basic_auth
 | 
				
			||||||
    log_tester = lambda {|log, access_log|
 | 
					    log_tester = lambda {|log, access_log|
 | 
				
			||||||
      assert_equal(1, log.length)
 | 
					      assert_equal(1, log.length)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -13,6 +13,11 @@ end
 | 
				
			||||||
require File.expand_path("utils.rb", File.dirname(__FILE__))
 | 
					require File.expand_path("utils.rb", File.dirname(__FILE__))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class TestWEBrickHTTPProxy < Test::Unit::TestCase
 | 
					class TestWEBrickHTTPProxy < Test::Unit::TestCase
 | 
				
			||||||
 | 
					  def teardown
 | 
				
			||||||
 | 
					    WEBrick::Utils::TimeoutHandler.terminate
 | 
				
			||||||
 | 
					    super
 | 
				
			||||||
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  def test_fake_proxy
 | 
					  def test_fake_proxy
 | 
				
			||||||
    assert_nil(WEBrick::FakeProxyURI.scheme)
 | 
					    assert_nil(WEBrick::FakeProxyURI.scheme)
 | 
				
			||||||
    assert_nil(WEBrick::FakeProxyURI.host)
 | 
					    assert_nil(WEBrick::FakeProxyURI.host)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -4,6 +4,11 @@ require "stringio"
 | 
				
			||||||
require "test/unit"
 | 
					require "test/unit"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class TestWEBrickHTTPRequest < Test::Unit::TestCase
 | 
					class TestWEBrickHTTPRequest < Test::Unit::TestCase
 | 
				
			||||||
 | 
					  def teardown
 | 
				
			||||||
 | 
					    WEBrick::Utils::TimeoutHandler.terminate
 | 
				
			||||||
 | 
					    super
 | 
				
			||||||
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  def test_simple_request
 | 
					  def test_simple_request
 | 
				
			||||||
    msg = <<-_end_of_message_
 | 
					    msg = <<-_end_of_message_
 | 
				
			||||||
GET /
 | 
					GET /
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -12,6 +12,11 @@ class TestWEBrickHTTPServer < Test::Unit::TestCase
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
  NoLog = WEBrick::Log.new(empty_log, WEBrick::BasicLog::WARN)
 | 
					  NoLog = WEBrick::Log.new(empty_log, WEBrick::BasicLog::WARN)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  def teardown
 | 
				
			||||||
 | 
					    WEBrick::Utils::TimeoutHandler.terminate
 | 
				
			||||||
 | 
					    super
 | 
				
			||||||
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  def test_mount
 | 
					  def test_mount
 | 
				
			||||||
    httpd = WEBrick::HTTPServer.new(
 | 
					    httpd = WEBrick::HTTPServer.new(
 | 
				
			||||||
      :Logger => NoLog,
 | 
					      :Logger => NoLog,
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -3,6 +3,11 @@ require "test/unit"
 | 
				
			||||||
require "webrick/utils"
 | 
					require "webrick/utils"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class TestWEBrickUtils < Test::Unit::TestCase
 | 
					class TestWEBrickUtils < Test::Unit::TestCase
 | 
				
			||||||
 | 
					  def teardown
 | 
				
			||||||
 | 
					    WEBrick::Utils::TimeoutHandler.terminate
 | 
				
			||||||
 | 
					    super
 | 
				
			||||||
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  def assert_expired(m)
 | 
					  def assert_expired(m)
 | 
				
			||||||
    Thread.handle_interrupt(Timeout::Error => :never, EX => :never) do
 | 
					    Thread.handle_interrupt(Timeout::Error => :never, EX => :never) do
 | 
				
			||||||
      assert_empty(m::TimeoutHandler.instance.instance_variable_get(:@timeout_info))
 | 
					      assert_empty(m::TimeoutHandler.instance.instance_variable_get(:@timeout_info))
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -3,6 +3,11 @@ require 'timeout'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
module TestXMLRPC
 | 
					module TestXMLRPC
 | 
				
			||||||
module WEBrick_Testing
 | 
					module WEBrick_Testing
 | 
				
			||||||
 | 
					  def teardown
 | 
				
			||||||
 | 
					    WEBrick::Utils::TimeoutHandler.terminate
 | 
				
			||||||
 | 
					    super
 | 
				
			||||||
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  def start_server(logger, config={})
 | 
					  def start_server(logger, config={})
 | 
				
			||||||
    raise "already started" if defined?(@__server) && @__server
 | 
					    raise "already started" if defined?(@__server) && @__server
 | 
				
			||||||
    @__started = false
 | 
					    @__started = false
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue