about summary refs log tree commit homepage
path: root/lib
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2009-02-13 00:08:33 -0800
committerEric Wong <normalperson@yhbt.net>2009-02-13 00:08:33 -0800
commit3d22c178d766d0601b75f5c0de7ee0696745c41c (patch)
tree4d0f7d3f6d689b13686861ddc496c4a35286f160 /lib
parent0bd2bf7c438eb4394b7a66ca0999ab896beccf95 (diff)
downloadunicorn-3d22c178d766d0601b75f5c0de7ee0696745c41c.tar.gz
Tempfile reuse was over-engineered and the problem was not
nearly as big a problem as initially thought.

Additionally, it could lead to a subtle bug in an applications
that link(2)s or rename(2)s the temporary file to a permanent
location _without_ closing it after the request is done.
Applications that suffer from the problem of directory bloat are
still free to modify ENV['TMPDIR'] to influence the creation of
Tempfiles.
Diffstat (limited to 'lib')
-rw-r--r--lib/unicorn/http_request.rb7
1 files changed, 3 insertions, 4 deletions
diff --git a/lib/unicorn/http_request.rb b/lib/unicorn/http_request.rb
index 47600d6..7e7166b 100644
--- a/lib/unicorn/http_request.rb
+++ b/lib/unicorn/http_request.rb
@@ -15,7 +15,7 @@ module Unicorn
 
     def initialize(logger)
       @logger = logger
-      @tempfile = @body = nil
+      @body = nil
       @buffer = ' ' * Const::CHUNK_SIZE # initial size, may grow
       @parser = HttpParser.new
       @params = Hash.new
@@ -24,7 +24,6 @@ module Unicorn
     def reset
       @parser.reset
       @params.clear
-      @body.truncate(0) rescue nil
       @body.close rescue nil
       @body = nil
     end
@@ -99,8 +98,7 @@ module Unicorn
         # small body, just use that
         @body = StringIO.new(http_body)
       else # huge body, put it in a tempfile
-        @tempfile ||= Tempfile.new(Const::UNICORN_TMP_BASE)
-        @body = File.open(@tempfile.path, "wb+")
+        @body = Tempfile.new(Const::UNICORN_TMP_BASE)
         @body.sync = true
         @body.syswrite(http_body)
       end
@@ -162,6 +160,7 @@ module Unicorn
 
       # Any errors means we should delete the file, including if the file
       # is dumped.  Truncate it ASAP to help avoid page flushes to disk.
+      @body.truncate(0) rescue nil
       reset
       false
     end