зеркало из https://github.com/github/ruby.git
webrick/httpserver.rb: Stop handling requests on shutdown
* lib/webrick/httpserver.rb (WEBrick::HTTPServer#run): stop handling requests on shutdown, even if the socket is readable and IO.select() returns true. [Fixes GH-607] * lib/webrick/server.rb (WEBrick::GenericServer#start): IO.select() raises ENOTSOCK on shutdown on Windows. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45872 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
b9f770ae8f
Коммит
719804b5df
|
@ -1,3 +1,12 @@
|
|||
Thu May 8 10:17:04 2014 Karsten Sperling <karsten@sperling.co.nz>
|
||||
|
||||
* lib/webrick/httpserver.rb (WEBrick::HTTPServer#run): stop
|
||||
handling requests on shutdown, even if the socket is readable
|
||||
and IO.select() returns true. [Fixes GH-607]
|
||||
|
||||
* lib/webrick/server.rb (WEBrick::GenericServer#start): IO.select()
|
||||
raises ENOTSOCK on shutdown on Windows.
|
||||
|
||||
Wed May 7 21:45:00 2014 Tanaka Akira <akr@fsij.org>
|
||||
|
||||
* ext/openssl/lib/openssl/ssl.rb (OpenSSL::SSL::SSLServer#accept):
|
||||
|
|
|
@ -73,10 +73,10 @@ module WEBrick
|
|||
timeout = @config[:RequestTimeout]
|
||||
while timeout > 0
|
||||
break if IO.select([sock], nil, nil, 0.5)
|
||||
timeout = 0 if @status != :Running
|
||||
break if @status != :Running
|
||||
timeout -= 0.5
|
||||
end
|
||||
raise HTTPStatus::EOFError if timeout <= 0
|
||||
raise HTTPStatus::EOFError if timeout <= 0 || @status != :Running
|
||||
raise HTTPStatus::EOFError if sock.eof?
|
||||
req.parse(sock)
|
||||
res.request_method = req.request_method
|
||||
|
|
|
@ -180,7 +180,7 @@ module WEBrick
|
|||
end
|
||||
}
|
||||
end
|
||||
rescue Errno::EBADF, IOError => ex
|
||||
rescue Errno::EBADF, Errno::ENOTSOCK, IOError => ex
|
||||
# if the listening socket was closed in GenericServer#shutdown,
|
||||
# IO::select raise it.
|
||||
rescue StandardError => ex
|
||||
|
|
|
@ -366,4 +366,27 @@ class TestWEBrickHTTPServer < Test::Unit::TestCase
|
|||
}
|
||||
assert_equal(requested, 1)
|
||||
end
|
||||
|
||||
def test_shutdown_with_busy_keepalive_connection
|
||||
requested = 0
|
||||
config = {
|
||||
:ServerName => "localhost",
|
||||
}
|
||||
TestWEBrick.start_httpserver(config){|server, addr, port, log|
|
||||
server.mount_proc("/", lambda {|req, res| res.body = "heffalump" })
|
||||
Thread.pass while server.status != :Running
|
||||
|
||||
Net::HTTP.start(addr, port) do |http|
|
||||
req = Net::HTTP::Get.new("/")
|
||||
http.request(req){|res| assert_equal('Keep-Alive', res['Connection'], log.call) }
|
||||
server.shutdown
|
||||
begin
|
||||
10.times {|n| http.request(req); requested += 1 }
|
||||
rescue
|
||||
# Errno::ECONNREFUSED or similar
|
||||
end
|
||||
end
|
||||
}
|
||||
assert_equal(0, requested, "Server responded to #{requested} requests after shutdown")
|
||||
end
|
||||
end
|
||||
|
|
Загрузка…
Ссылка в новой задаче