* lib/webrick/server.rb: Invoke setup_shutdown_pipe in start method
instead of listen method. [ruby-core:68476] [Bug #10956] Reported by Shintaro Kojima. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49917 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
acc17bfc0f
commit
ab0a64e1c8
@ -1,3 +1,9 @@
|
|||||||
|
Tue Mar 10 20:03:41 2015 Tanaka Akira <akr@fsij.org>
|
||||||
|
|
||||||
|
* lib/webrick/server.rb: Invoke setup_shutdown_pipe in start method
|
||||||
|
instead of listen method.
|
||||||
|
[ruby-core:68476] [Bug #10956] Reported by Shintaro Kojima.
|
||||||
|
|
||||||
Tue Mar 10 17:27:27 2015 Koichi Sasada <ko1@atdot.net>
|
Tue Mar 10 17:27:27 2015 Koichi Sasada <ko1@atdot.net>
|
||||||
|
|
||||||
* thread.c (thread_join): Fixnum (except TAG_FATAL) and
|
* thread.c (thread_join): Fixnum (except TAG_FATAL) and
|
||||||
|
@ -131,7 +131,6 @@ module WEBrick
|
|||||||
|
|
||||||
def listen(address, port)
|
def listen(address, port)
|
||||||
@listeners += Utils::create_listeners(address, port)
|
@listeners += Utils::create_listeners(address, port)
|
||||||
setup_shutdown_pipe
|
|
||||||
end
|
end
|
||||||
|
|
||||||
##
|
##
|
||||||
@ -159,6 +158,8 @@ module WEBrick
|
|||||||
raise ServerError, "already started." if @status != :Stop
|
raise ServerError, "already started." if @status != :Stop
|
||||||
server_type = @config[:ServerType] || SimpleServer
|
server_type = @config[:ServerType] || SimpleServer
|
||||||
|
|
||||||
|
setup_shutdown_pipe
|
||||||
|
|
||||||
server_type.start{
|
server_type.start{
|
||||||
@logger.info \
|
@logger.info \
|
||||||
"#{self.class}#start: pid=#{$$} port=#{@config[:Port]}"
|
"#{self.class}#start: pid=#{$$} port=#{@config[:Port]}"
|
||||||
@ -330,6 +331,7 @@ module WEBrick
|
|||||||
|
|
||||||
def cleanup_shutdown_pipe(shutdown_pipe)
|
def cleanup_shutdown_pipe(shutdown_pipe)
|
||||||
@shutdown_pipe = nil
|
@shutdown_pipe = nil
|
||||||
|
return if !shutdown_pipe
|
||||||
shutdown_pipe.each {|io|
|
shutdown_pipe.each {|io|
|
||||||
if !io.closed?
|
if !io.closed?
|
||||||
begin
|
begin
|
||||||
|
@ -97,7 +97,7 @@ class TestWEBrickServer < Test::Unit::TestCase
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_restart
|
def test_restart_after_shutdown
|
||||||
address = '127.0.0.1'
|
address = '127.0.0.1'
|
||||||
port = 0
|
port = 0
|
||||||
log = []
|
log = []
|
||||||
@ -128,4 +128,30 @@ class TestWEBrickServer < Test::Unit::TestCase
|
|||||||
assert_join_threads([client_thread, server_thread])
|
assert_join_threads([client_thread, server_thread])
|
||||||
assert_equal([], log)
|
assert_equal([], log)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_restart_after_stop
|
||||||
|
log = Object.new
|
||||||
|
class << log
|
||||||
|
include Test::Unit::Assertions
|
||||||
|
def <<(msg)
|
||||||
|
flunk "unexpected log: #{msg.inspect}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
warn_flunk = WEBrick::Log.new(log, WEBrick::BasicLog::WARN)
|
||||||
|
server = WEBrick::HTTPServer.new(
|
||||||
|
:BindAddress => '0.0.0.0',
|
||||||
|
:Port => 0,
|
||||||
|
:Logger => warn_flunk)
|
||||||
|
2.times {
|
||||||
|
server_thread = Thread.start {
|
||||||
|
server.start
|
||||||
|
}
|
||||||
|
client_thread = Thread.start {
|
||||||
|
sleep 0.1 until server.status == :Running || !server_thread.status
|
||||||
|
server.stop
|
||||||
|
sleep 0.1 until server.status == :Stop || !server_thread.status
|
||||||
|
}
|
||||||
|
assert_join_threads([client_thread, server_thread])
|
||||||
|
}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user