From: "naruse (Yui NARUSE)" Date: 2012-04-12T10:53:53+09:00 Subject: [ruby-core:44299] [ruby-trunk - Feature #6236][Assigned] WEBrick::HTTPServer swallows Exception Issue #6236 has been updated by naruse (Yui NARUSE). Status changed from Closed to Assigned r35303 looks buggy. WERBrick::GenericServer#stop's is a method to deny a new connection. Even if the method is called, the server is still alive. To kill the server, calling shutdown is required. In other words, the status of a server is changing like Stop -> Running -> Shutdown -> Stop (the name and the functions is confusing arround shutdown/stop...) The relation between methods and status is * start: Stop -> Running * stop: Running -> Shutdown * shutdown: Running -> Shutdown -> Stop This effects especially when ServerType is Thread. In such case it must wait after calling shutdown until the server status become Stop. A patch is following: diff --git a/lib/webrick/server.rb b/lib/webrick/server.rb index 22b91ad..2eabf5d 100644 --- a/lib/webrick/server.rb +++ b/lib/webrick/server.rb @@ -143,6 +143,7 @@ module WEBrick end ensure + @status = :Shutdown @logger.info "going to shutdown ..." thgroup.list.each{|th| th.join if th[:WEBrickThread] } call_callback(:StopCallback) @@ -157,7 +158,7 @@ module WEBrick def stop if @status == :Running - @status = :Stop + @status = :Shutdown end end ---------------------------------------- Feature #6236: WEBrick::HTTPServer swallows Exception https://bugs.ruby-lang.org/issues/6236#change-25846 Author: regularfry (Alex Young) Status: Assigned Priority: Normal Assignee: nahi (Hiroshi Nakamura) Category: lib Target version: 2.0.0 At the moment when using WEBrick you've always got to remember to define a signal handler to be able to kill the server when you're done with it. This is annoying and makes it more painful to use than it should be, because if you realise you've forgotten to define a trap("INT") handler after you've started the server, all you can do is kill -9 the process. This also catches out people learning the library more than it should. It shouldn't be the web server's job to take over process management, but that's what it ends up doing. The reason this happens is because webrick/server.rb uses `rescue Exception` around its accept loop. This is more broad than it should be. The attached patch replaces this with a `rescue StandardError`, and causes other Exception subclasses to be logged and re-raised. This makes WEBrick::HTTPServer somewhat more friendly to use at the command-line. If you Ctrl-c out of a `server.start` loop with this patch applied, you can't restart the server because it leaves internal state lying around, but I think it's still an improvement over the current situation. -- http://bugs.ruby-lang.org/