From 3d22c178d766d0601b75f5c0de7ee0696745c41c Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Fri, 13 Feb 2009 00:08:33 -0800 Subject: Remove tempfile reuse from HttpRequest, upload tests 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. --- lib/unicorn/http_request.rb | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'lib') 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 -- cgit v1.2.3-24-ge0c7