summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog6
-rw-r--r--lib/webrick/server.rb4
-rw-r--r--test/webrick/test_server.rb28
3 files changed, 36 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index a7ccb6b86c7..acf9099dec5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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>
* thread.c (thread_join): Fixnum (except TAG_FATAL) and
diff --git a/lib/webrick/server.rb b/lib/webrick/server.rb
index f1f0d81fdf0..8b53939c525 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 043d439cb7c..ea237c6166b 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