From mboxrd@z Thu Jan 1 00:00:00 1970 Delivered-To: chneukirchen@gmail.com Received: by 10.140.128.1 with SMTP id a1cs14933rvd; Sun, 7 Mar 2010 17:12:09 -0800 (PST) Received-SPF: pass (google.com: domain of 36E6USwwIChcABE9x8C1EFBAL4yG.A1GExz7-01I183BB3813EBHCF.zB9@groups.bounces.google.com designates 10.115.101.19 as permitted sender) client-ip=10.115.101.19; Authentication-Results: mr.google.com; spf=pass (google.com: domain of 36E6USwwIChcABE9x8C1EFBAL4yG.A1GExz7-01I183BB3813EBHCF.zB9@groups.bounces.google.com designates 10.115.101.19 as permitted sender) smtp.mail=36E6USwwIChcABE9x8C1EFBAL4yG.A1GExz7-01I183BB3813EBHCF.zB9@groups.bounces.google.com; dkim=pass header.i=36E6USwwIChcABE9x8C1EFBAL4yG.A1GExz7-01I183BB3813EBHCF.zB9@groups.bounces.google.com Received: from mr.google.com ([10.115.101.19]) by 10.115.101.19 with SMTP id d19mr1820685wam.5.1268010729785 (num_hops = 1); Sun, 07 Mar 2010 17:12:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=beta; h=domainkey-signature:received:x-beenthere:received:received:received :received:received-spf:received:date:from:to:subject:message-id :references:mime-version:in-reply-to:user-agent :x-original-authentication-results:x-original-sender:reply-to :precedence:mailing-list:list-id:list-post:list-help:list-archive :x-thread-url:x-message-url:sender:list-subscribe:list-unsubscribe :content-type:content-disposition; bh=PcF0WPoboiTJY7ZlVvVkbVAa2z6H9zcHGT02kzNcPuk=; b=0ExiArFOD9GoUNdH+Pu4Tn6jbgvFEWhFuiG9oDGvUpShIbaNI1RmLILNdwdxQ4gAMT ZVcF7hQEdGyCHpIRPljPFyy7u6GyJcf85RlDnVKEYMvws5NqxJaQiYvfvg/QkHYMeBtP H5R5vc68VxwCjJa1L0fOSnkmSob3CRerZBHR0= DomainKey-Signature: a=rsa-sha1; c=nofws; d=googlegroups.com; s=beta; h=x-beenthere:received-spf:date:from:to:subject:message-id:references :mime-version:in-reply-to:user-agent :x-original-authentication-results:x-original-sender:reply-to :precedence:mailing-list:list-id:list-post:list-help:list-archive :x-thread-url:x-message-url:sender:list-subscribe:list-unsubscribe :content-type:content-disposition; b=VDaF/04ZOsHutcWAmFJI4KAtYLBWKeuIdI1Qbrp0OX1+3GE0KqBowpLrwSuVyjacpy dijIoJsDN6qpXkXwrN3Jsx12H+MeHA8uxRHkuNTzvgooP0X0KoqFwySbgch02nDgzbzJ Vkjo1g9VRWUXzRc7G/g861c9dYIKvWuO0w6eA= Received: by 10.115.101.19 with SMTP id d19mr219387wam.5.1268010728551; Sun, 07 Mar 2010 17:12:08 -0800 (PST) X-BeenThere: rack-devel@googlegroups.com Received: by 10.114.33.26 with SMTP id g26ls1295407wag.3.p; Sun, 07 Mar 2010 17:12:07 -0800 (PST) Received: by 10.114.6.21 with SMTP id 21mr836762waf.25.1268010726992; Sun, 07 Mar 2010 17:12:06 -0800 (PST) Received: by 10.114.6.21 with SMTP id 21mr836761waf.25.1268010726936; Sun, 07 Mar 2010 17:12:06 -0800 (PST) Return-Path: Received: from dcvr.yhbt.net (dcvr.yhbt.net [64.71.152.64]) by gmr-mx.google.com with ESMTP id 19si1150629pzk.11.2010.03.07.17.12.06; Sun, 07 Mar 2010 17:12:06 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of normalperson@yhbt.net designates 64.71.152.64 as permitted sender) client-ip=64.71.152.64; Received: from localhost (unknown [127.0.2.5]) by dcvr.yhbt.net (Postfix) with ESMTP id E2DC81F73A; Mon, 8 Mar 2010 01:12:05 +0000 (UTC) Date: Sun, 7 Mar 2010 17:12:04 -0800 From: Eric Wong To: rack-devel@googlegroups.com Subject: Re: Not cleaning up tempfiles for multipart? Message-ID: <20100308011204.GA19119@dcvr.yhbt.net> References: <20100306075548.GB6474@dcvr.yhbt.net> <44f3f951-889e-45ec-ae46-40a371329a9e@e1g2000yqh.googlegroups.com> <20100308002217.GB18365@dcvr.yhbt.net> MIME-Version: 1.0 In-Reply-To: <20100308002217.GB18365@dcvr.yhbt.net> User-Agent: Mutt/1.5.18 (2008-05-17) X-Original-Authentication-Results: gmr-mx.google.com; spf=pass (google.com: best guess record for domain of normalperson@yhbt.net designates 64.71.152.64 as permitted sender) smtp.mail=normalperson@yhbt.net X-Original-Sender: normalperson@yhbt.net Reply-To: rack-devel@googlegroups.com Precedence: list Mailing-list: list rack-devel@googlegroups.com; contact rack-devel+owners@googlegroups.com List-ID: List-Post: , List-Help: , List-Archive: X-Thread-Url: http://groups.google.com/group/rack-devel/t/6eb2bc7a1f8c072c X-Message-Url: http://groups.google.com/group/rack-devel/msg/f6f7c155df5a89cd Sender: rack-devel@googlegroups.com List-Subscribe: , List-Unsubscribe: , Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Eric Wong wrote: > Charles Oliver Nutter wrote: > > I'm certainly willing to help fix Rack, but I'm not sure where would > > be the best place to close! the tempfile. > > I suspect it needs to be done a per-handler basis or inside the server. > rack/handler/fastcgi.rb and rack/handler/lsws.rb both create > RewindableInput objects and close them in the ensure block. I guess this deals with wonky multipart uploads that browsers still generate these days[1]. Ugh, yeah, it's nasty... The comment below in _call is very important. 1. Ensure all tempfiles created by Rack go into an array in env, probably env["rack.tempfiles"]: tempfile = Tempfile.new("foo") (env["rack.tempfiles"] ||= []) << tempfile 2. Have a middleware wrap everything, including the response body: class TempfileReaper < Struct.new(:app, :env, :body) # --------------- in config.ru ----------- # use TempfileReaper # run MyApp.new def initialize(app) super(app) end # we wrap the entire response body later on, so dup it for # reentrancy. You can actually avoid the enforced dup as # an optimization, probably... def call(env) dup._call(env) end # used when wrapping the response body def each(&block) body.each { |chunk| yield chunk } end # the Rack server should call this (when we're the body) def close tempfiles = env["rack.tempfiles"] if tempfiles tempfiles.each { |tmp| tmp.close! rescue nil } end end # wrap the normal application call, saving env def _call(env) self.env = env # XXX VERY IMPORTANT: # you need to ensure env stays the same throughout the request, # some middlewares overwrite/replace it instead of merge!-ing into it status, headers, body = app.call(env) self.body = body [ status, headers, self ] end end [1] - in my world of singing and dancing penguins, my clients use "curl -T" to send proper PUT requests :) -- Eric Wong