about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2009-05-04 06:08:36 +0000
committerEric Wong <normalperson@yhbt.net>2009-05-04 06:08:36 +0000
commit17dc99cc5c3a3fc59145724059f36c5c907f6c3f (patch)
treec2b96cb928fd784e6064bfafa90f18e9da9f9279
parentdf27bb444e04cdd36d74010290e9270f129eeb3c (diff)
downloadunicorn-17dc99cc5c3a3fc59145724059f36c5c907f6c3f.tar.gz
These potentially leaves an open file handle around until the
next request hits the process, but this makes the common case
faster.
-rw-r--r--lib/unicorn.rb2
-rw-r--r--lib/unicorn/http_request.rb19
-rw-r--r--test/unit/test_request.rb1
3 files changed, 8 insertions, 14 deletions
diff --git a/lib/unicorn.rb b/lib/unicorn.rb
index 0b8ac5e..bcd0a91 100644
--- a/lib/unicorn.rb
+++ b/lib/unicorn.rb
@@ -430,8 +430,6 @@ module Unicorn
       client.close rescue nil
       logger.error "Read error: #{e.inspect}"
       logger.error e.backtrace.join("\n")
-    ensure
-      @request.reset
     end
 
     # gets rid of stuff the worker has no business keeping track of
diff --git a/lib/unicorn/http_request.rb b/lib/unicorn/http_request.rb
index e786d79..c356576 100644
--- a/lib/unicorn/http_request.rb
+++ b/lib/unicorn/http_request.rb
@@ -38,17 +38,6 @@ module Unicorn
 
     def initialize(logger)
       @logger = logger
-      reset
-    end
-
-    def reset
-      input = PARAMS[Const::RACK_INPUT]
-      if input != NULL_IO
-        input.close rescue nil
-        input.close! rescue nil
-      end
-      PARAMS.clear
-      PARSER.reset
     end
 
     # Does the majority of the IO processing.  It has been written in
@@ -65,6 +54,14 @@ module Unicorn
     # This does minimal exception trapping and it is up to the caller
     # to handle any socket errors (e.g. user aborted upload).
     def read(socket)
+      # reset the parser
+      unless NULL_IO == (input = PARAMS[Const::RACK_INPUT]) # unlikely
+        input.close rescue nil
+        input.close! rescue nil
+      end
+      PARAMS.clear
+      PARSER.reset
+
       # From http://www.ietf.org/rfc/rfc3875:
       # "Script authors should be aware that the REMOTE_ADDR and
       #  REMOTE_HOST meta-variables (see sections 4.1.8 and 4.1.9)
diff --git a/test/unit/test_request.rb b/test/unit/test_request.rb
index a6cb13c..0bfff7d 100644
--- a/test/unit/test_request.rb
+++ b/test/unit/test_request.rb
@@ -77,7 +77,6 @@ class RequestTest < Test::Unit::TestCase
       client = MockRequest.new("GET #{abs_uri} HTTP/1.1\r\n" \
                                "Host: foo\r\n\r\n")
       assert_raises(HttpParserError) { @request.read(client) }
-      @request.reset
     end
   end