From ab0a64e1c87d8fd9d0a6ee8bb6bc084d0a6f482b Mon Sep 17 00:00:00 2001 From: akr Date: Tue, 10 Mar 2015 11:05:21 +0000 Subject: [PATCH] * 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 --- ChangeLog | 6 ++++++ lib/webrick/server.rb | 4 +++- test/webrick/test_server.rb | 28 +++++++++++++++++++++++++++- 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index a7ccb6b86c..acf9099dec 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Tue Mar 10 20:03:41 2015 Tanaka Akira + + * 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 * thread.c (thread_join): Fixnum (except TAG_FATAL) and diff --git a/lib/webrick/server.rb b/lib/webrick/server.rb index f1f0d81fdf..8b53939c52 100644 --- a/lib/webrick/server.rb +++ b/lib/webrick/server.rb @@ -131,7 +131,6 @@ module WEBrick def listen(address, port) @listeners += Utils::create_listeners(address, port) - setup_shutdown_pipe end ## @@ -159,6 +158,8 @@ module WEBrick raise ServerError, "already started." if @status != :Stop server_type = @config[:ServerType] || SimpleServer + setup_shutdown_pipe + server_type.start{ @logger.info \ "#{self.class}#start: pid=#{$$} port=#{@config[:Port]}" @@ -330,6 +331,7 @@ module WEBrick def cleanup_shutdown_pipe(shutdown_pipe) @shutdown_pipe = nil + return if !shutdown_pipe shutdown_pipe.each {|io| if !io.closed? begin diff --git a/test/webrick/test_server.rb b/test/webrick/test_server.rb index 043d439cb7..ea237c6166 100644 --- a/test/webrick/test_server.rb +++ b/test/webrick/test_server.rb @@ -97,7 +97,7 @@ class TestWEBrickServer < Test::Unit::TestCase end end - def test_restart + def test_restart_after_shutdown address = '127.0.0.1' port = 0 log = [] @@ -128,4 +128,30 @@ class TestWEBrickServer < Test::Unit::TestCase assert_join_threads([client_thread, server_thread]) assert_equal([], log) 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