[前][次][番号順一覧][スレッド一覧]

ruby-changes:33791

From: nobu <ko1@a...>
Date: Thu, 8 May 2014 10:17:15 +0900 (JST)
Subject: [ruby-changes:33791] nobu:r45872 (trunk): webrick/httpserver.rb: Stop handling requests on shutdown

nobu	2014-05-08 10:17:07 +0900 (Thu, 08 May 2014)

  New Revision: 45872

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=45872

  Log:
    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.

  Modified files:
    trunk/ChangeLog
    trunk/lib/webrick/httpserver.rb
    trunk/lib/webrick/server.rb
    trunk/test/webrick/test_httpserver.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 45871)
+++ ChangeLog	(revision 45872)
@@ -1,3 +1,12 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Thu May  8 10:17:04 2014  Karsten Sperling  <karsten@s...>
+
+	* 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@f...>
 
 	* ext/openssl/lib/openssl/ssl.rb (OpenSSL::SSL::SSLServer#accept):
Index: lib/webrick/httpserver.rb
===================================================================
--- lib/webrick/httpserver.rb	(revision 45871)
+++ lib/webrick/httpserver.rb	(revision 45872)
@@ -73,10 +73,10 @@ module WEBrick https://github.com/ruby/ruby/blob/trunk/lib/webrick/httpserver.rb#L73
           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
Index: lib/webrick/server.rb
===================================================================
--- lib/webrick/server.rb	(revision 45871)
+++ lib/webrick/server.rb	(revision 45872)
@@ -180,7 +180,7 @@ module WEBrick https://github.com/ruby/ruby/blob/trunk/lib/webrick/server.rb#L180
                   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
Index: test/webrick/test_httpserver.rb
===================================================================
--- test/webrick/test_httpserver.rb	(revision 45871)
+++ test/webrick/test_httpserver.rb	(revision 45872)
@@ -366,4 +366,27 @@ class TestWEBrickHTTPServer < Test::Unit https://github.com/ruby/ruby/blob/trunk/test/webrick/test_httpserver.rb#L366
     }
     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

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]