From: Eric Wong <e@80x24.org>
To: "Mulvaney, Mike" <MMulvaney@bna.com>
Cc: "unicorn-public@bogomips.org" <unicorn-public@bogomips.org>
Subject: Re: TeeInput leaks file handles/space
Date: Wed, 22 Apr 2015 19:16:08 +0000 [thread overview]
Message-ID: <20150422191608.GA31363@dcvr.yhbt.net> (raw)
In-Reply-To: <CY1PR0301MB07803D33C70E594F058BB0FFA4EE0@CY1PR0301MB0780.namprd03.prod.outlook.com>
"Mulvaney, Mike" <MMulvaney@bna.com> wrote:
> That looks reasonable to me -- this way you would only have one file
> still open per process at a maximum, right? I think that's a good
> solution.
Right.
Below is a barely-tested alternative patch for Rack::TempfileReaper,
for Rack 1.6+ users only. I'm not sure how prevalent 1.6+ was only
released in December 2014...
It's more standardized, but maybe Rack 1.6 isn't prevalent enough, yet.
What do you think?
(Sorry, in a rush, no commit message, yet)
diff --git a/lib/unicorn/tee_input.rb b/lib/unicorn/tee_input.rb
index 637c583..7f6baa2 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
+ 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
next prev parent reply other threads:[~2015-04-22 19:16 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-04-22 16:42 TeeInput leaks file handles/space Mulvaney, Mike
2015-04-22 18:38 ` Eric Wong
2015-04-22 19:10 ` Mulvaney, Mike
2015-04-22 19:16 ` Eric Wong [this message]
2015-04-22 19:24 ` Mulvaney, Mike
2015-04-24 3:08 ` Eric Wong
2015-04-24 11:56 ` Mulvaney, Mike
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://yhbt.net/unicorn/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20150422191608.GA31363@dcvr.yhbt.net \
--to=e@80x24.org \
--cc=MMulvaney@bna.com \
--cc=unicorn-public@bogomips.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).