* [PATCH 0/2] Rack::TempfileReaper support
@ 2015-04-24 3:02 Eric Wong
2015-04-24 3:02 ` [PATCH 1/2] tee_input: support for Rack::TempfileReaper middleware Eric Wong
2015-04-24 3:02 ` [PATCH 2/2] support TempfileReaper in deployment and development envs Eric Wong
0 siblings, 2 replies; 3+ messages in thread
From: Eric Wong @ 2015-04-24 3:02 UTC (permalink / raw)
To: unicorn-public; +Cc: Mike Mulvaney
These will be in the upcoming 4.9 release, as well as the 5.x
release which drops old cruft and 1.8 support. I've decided
to use 4.9 instead of 4.8.4 since this does change the feature
set slightly.
Eric Wong (2):
tee_input: support for Rack::TempfileReaper middleware
support TempfileReaper in deployment and development envs
lib/unicorn.rb | 2 ++
lib/unicorn/tee_input.rb | 9 ++++++++-
lib/unicorn/tmpio.rb | 3 +++
test/unit/test_tee_input.rb | 10 ++++++++++
4 files changed, 23 insertions(+), 1 deletion(-)
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH 1/2] tee_input: support for Rack::TempfileReaper middleware
2015-04-24 3:02 [PATCH 0/2] Rack::TempfileReaper support Eric Wong
@ 2015-04-24 3:02 ` Eric Wong
2015-04-24 3:02 ` [PATCH 2/2] support TempfileReaper in deployment and development envs Eric Wong
1 sibling, 0 replies; 3+ messages in thread
From: Eric Wong @ 2015-04-24 3:02 UTC (permalink / raw)
To: unicorn-public; +Cc: Mike Mulvaney, Eric Wong
Rack::TempfileReaper was added in rack 1.6 to cleanup temporary
files. Make Unicorn::TmpIO ducktype-compatible so
Rack::TempfileReaper may be used to free up space used by temporary
buffer files.
Ref: <CY1PR0301MB078011EB5A22B733EB222A45A4EE0@CY1PR0301MB0780.namprd03.prod.outlook.com>
Reported-by: Mike Mulvaney <MMulvaney@bna.com>
---
lib/unicorn/tee_input.rb | 9 ++++++++-
lib/unicorn/tmpio.rb | 3 +++
test/unit/test_tee_input.rb | 10 ++++++++++
3 files changed, 21 insertions(+), 1 deletion(-)
diff --git a/lib/unicorn/tee_input.rb b/lib/unicorn/tee_input.rb
index 637c583..3c6d18a 100644
--- a/lib/unicorn/tee_input.rb
+++ b/lib/unicorn/tee_input.rb
@@ -28,13 +28,20 @@ class Unicorn::TeeInput < Unicorn::StreamInput
@@client_body_buffer_size
end
+ # for Rack::TempfileReaper in rack 1.6+
+ def new_tmpio # :nodoc:
+ tmpio = Unicorn::TmpIO.new
+ (@parser.env['rack.tempfiles'] ||= []) << tmpio
+ tmpio
+ end
+
# Initializes a new TeeInput object. You normally do not have to call
# this unless you are writing an HTTP server.
def initialize(socket, request)
@len = request.content_length
super
@tmp = @len && @len <= @@client_body_buffer_size ?
- StringIO.new("") : Unicorn::TmpIO.new
+ StringIO.new("") : new_tmpio
end
# :call-seq:
diff --git a/lib/unicorn/tmpio.rb b/lib/unicorn/tmpio.rb
index c97979a..db88ed3 100644
--- a/lib/unicorn/tmpio.rb
+++ b/lib/unicorn/tmpio.rb
@@ -21,4 +21,7 @@ class Unicorn::TmpIO < File
fp.sync = true
fp
end
+
+ # pretend we're Tempfile for Rack::TempfileReaper
+ alias close! close
end
diff --git a/test/unit/test_tee_input.rb b/test/unit/test_tee_input.rb
index 0c2c941..4647e66 100644
--- a/test/unit/test_tee_input.rb
+++ b/test/unit/test_tee_input.rb
@@ -29,6 +29,13 @@ class TestTeeInput < Test::Unit::TestCase
end while true
end
+ def check_tempfiles
+ tmp = @parser.env["rack.tempfiles"]
+ assert_instance_of Array, tmp
+ assert_operator tmp.size, :>=, 1
+ assert_instance_of Unicorn::TmpIO, tmp[0]
+ end
+
def test_gets_long
r = init_request("hello", 5 + (4096 * 4 * 3) + "#$/foo#$/".size)
ti = TeeInput.new(@rd, r)
@@ -106,6 +113,7 @@ class TestTeeInput < Test::Unit::TestCase
assert_kind_of File, ti.tmp
assert_equal 0, ti.tmp.pos
assert_equal Unicorn::Const::MAX_BODY + 1, ti.size
+ check_tempfiles
end
def test_read_in_full_if_content_length
@@ -148,6 +156,7 @@ class TestTeeInput < Test::Unit::TestCase
assert_nil ti.read(1)
pid, status = Process.waitpid2(pid)
assert status.success?
+ check_tempfiles
end
def test_chunked
@@ -183,6 +192,7 @@ class TestTeeInput < Test::Unit::TestCase
status = nil
pid, status = Process.waitpid2(pid)
assert status.success?
+ check_tempfiles
end
def test_chunked_ping_pong
--
EW
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH 2/2] support TempfileReaper in deployment and development envs
2015-04-24 3:02 [PATCH 0/2] Rack::TempfileReaper support Eric Wong
2015-04-24 3:02 ` [PATCH 1/2] tee_input: support for Rack::TempfileReaper middleware Eric Wong
@ 2015-04-24 3:02 ` Eric Wong
1 sibling, 0 replies; 3+ messages in thread
From: Eric Wong @ 2015-04-24 3:02 UTC (permalink / raw)
To: unicorn-public; +Cc: Mike Mulvaney, Eric Wong
rack 1.6 added a TempfileReaper middleware to cleanup temporary
files. Enable it by default for users running rack 1.6 or later
to avoid leaving temporary files around.
---
lib/unicorn.rb | 2 ++
1 file changed, 2 insertions(+)
diff --git a/lib/unicorn.rb b/lib/unicorn.rb
index 467245d..9fdcb8e 100644
--- a/lib/unicorn.rb
+++ b/lib/unicorn.rb
@@ -65,6 +65,7 @@ module Unicorn
use Rack::CommonLogger, $stderr
use Rack::ShowExceptions
use Rack::Lint
+ use Rack::TempfileReaper if Rack.const_defined?(:TempfileReaper)
run inner_app
end.to_app
when "deployment"
@@ -72,6 +73,7 @@ module Unicorn
use Rack::ContentLength
use Rack::Chunked
use Rack::CommonLogger, $stderr
+ use Rack::TempfileReaper if Rack.const_defined?(:TempfileReaper)
run inner_app
end.to_app
else
--
EW
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2015-04-24 3:02 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-04-24 3:02 [PATCH 0/2] Rack::TempfileReaper support Eric Wong
2015-04-24 3:02 ` [PATCH 1/2] tee_input: support for Rack::TempfileReaper middleware Eric Wong
2015-04-24 3:02 ` [PATCH 2/2] support TempfileReaper in deployment and development envs Eric Wong
Code repositories for project(s) associated with this public inbox
https://yhbt.net/unicorn.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).