mirror of
https://github.com/puma/puma.git
synced 2022-11-09 13:48:40 -05:00
move socket close into ensure
git-svn-id: svn+ssh://rubyforge.org/var/svn/mongrel/trunk@784 19e92222-5c0b-0410-8929-a290d50e31e9
This commit is contained in:
parent
2ad24e46f0
commit
3bdf6c88b5
4 changed files with 56 additions and 42 deletions
|
@ -89,7 +89,10 @@ module Mongrel
|
|||
# socket.accept calls in order to give the server a cheap throttle time. It defaults to 0 and
|
||||
# actually if it is 0 then the sleep is not done at all.
|
||||
def initialize(host, port, num_processors=950, throttle=0, timeout=60)
|
||||
|
||||
tries = 0
|
||||
@socket = TCPServer.new(host, port)
|
||||
|
||||
@classifier = URIClassifier.new
|
||||
@host = host
|
||||
@port = port
|
||||
|
@ -211,12 +214,12 @@ module Mongrel
|
|||
STDERR.puts "#{Time.now}: Reaping #{@workers.list.length} threads for slow workers because of '#{reason}'"
|
||||
error_msg = "Mongrel timed out this thread: #{reason}"
|
||||
mark = Time.now
|
||||
@workers.list.each do |w|
|
||||
w[:started_on] = Time.now if not w[:started_on]
|
||||
@workers.list.each do |worker|
|
||||
worker[:started_on] = Time.now if not worker[:started_on]
|
||||
|
||||
if mark - w[:started_on] > @timeout + @throttle
|
||||
if mark - worker[:started_on] > @timeout + @throttle
|
||||
STDERR.puts "Thread #{w.inspect} is too old, killing."
|
||||
w.raise(TimeoutError.new(error_msg))
|
||||
worker.raise(TimeoutError.new(error_msg))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -264,6 +267,7 @@ module Mongrel
|
|||
end
|
||||
|
||||
@acceptor = Thread.new do
|
||||
begin
|
||||
while true
|
||||
begin
|
||||
client = @socket.accept
|
||||
|
@ -286,7 +290,6 @@ module Mongrel
|
|||
sleep @throttle/100.0 if @throttle > 0
|
||||
end
|
||||
rescue StopServer
|
||||
@socket.close
|
||||
break
|
||||
rescue Errno::EMFILE
|
||||
reap_dead_workers("too many open files")
|
||||
|
@ -300,6 +303,10 @@ module Mongrel
|
|||
end
|
||||
end
|
||||
graceful_shutdown
|
||||
ensure
|
||||
@socket.close
|
||||
# STDERR.puts "#{Time.now}: Closed socket."
|
||||
end
|
||||
end
|
||||
|
||||
return @acceptor
|
||||
|
|
|
@ -9,7 +9,9 @@ require 'test/testhelp'
|
|||
class RedirectHandlerTest < Test::Unit::TestCase
|
||||
|
||||
def setup
|
||||
redirect_test_io do
|
||||
@server = Mongrel::HttpServer.new('127.0.0.1', 9998)
|
||||
end
|
||||
@server.run
|
||||
@client = Net::HTTP.new('127.0.0.1', 9998)
|
||||
end
|
||||
|
|
|
@ -38,7 +38,9 @@ end
|
|||
|
||||
class RequestProgressTest < Test::Unit::TestCase
|
||||
def setup
|
||||
redirect_test_io do
|
||||
@server = Mongrel::HttpServer.new("127.0.0.1", 9998)
|
||||
end
|
||||
@handler = UploadBeginHandler.new
|
||||
@server.register("/upload", @handler)
|
||||
@server.run
|
||||
|
|
|
@ -23,8 +23,11 @@ class WebServerTest < Test::Unit::TestCase
|
|||
def setup
|
||||
@valid_request = "GET / HTTP/1.1\r\nHost: www.zedshaw.com\r\nContent-Type: text/plain\r\n\r\n"
|
||||
|
||||
redirect_test_io do
|
||||
# We set num_processors=1 so that we can test the reaping code
|
||||
@server = HttpServer.new("127.0.0.1", 9998, num_processors=1)
|
||||
end
|
||||
|
||||
@tester = TestHandler.new
|
||||
@server.register("/test", @tester)
|
||||
redirect_test_io do
|
||||
|
|
Loading…
Reference in a new issue