From mboxrd@z Thu Jan 1 00:00:00 1970 Delivered-To: chneukirchen@gmail.com Received: by 10.229.238.84 with SMTP id kr20cs89611qcb; Tue, 21 Feb 2012 20:08:32 -0800 (PST) Return-Path: Received-SPF: pass (google.com: domain of rack-devel+bncCI6A2tfGFBC-1JH6BBoEms9HUw@googlegroups.com designates 10.50.34.201 as permitted sender) client-ip=10.50.34.201; Authentication-Results: mr.google.com; spf=pass (google.com: domain of rack-devel+bncCI6A2tfGFBC-1JH6BBoEms9HUw@googlegroups.com designates 10.50.34.201 as permitted sender) smtp.mail=rack-devel+bncCI6A2tfGFBC-1JH6BBoEms9HUw@googlegroups.com; dkim=pass header.i=rack-devel+bncCI6A2tfGFBC-1JH6BBoEms9HUw@googlegroups.com Received: from mr.google.com ([10.50.34.201]) by 10.50.34.201 with SMTP id b9mr20202037igj.6.1329883712322 (num_hops = 1); Tue, 21 Feb 2012 20:08:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=beta; h=x-beenthere:mime-version:date:user-agent:x-http-useragent :message-id:subject:from:to:x-original-sender :x-original-authentication-results:reply-to:precedence:mailing-list :list-id:x-google-group-id:list-post:list-help:list-archive:sender :list-subscribe:list-unsubscribe:content-type; bh=pkBlNKrktmHeyZjlzJBRIzLujLr9ijdc6GF3ju2FhO8=; b=05M0DluxTpY2oAlkn0zC/KefRmg3sooJpBTTaw/N4u5RNpQghR4L3ELiweE4o37ke2 fjzO5YVbNFsIuCZqe72LwhQvdWikhT5AAtIGamsydNbmDZKcZfCih/oKr6/EhzgRwCaj RAMW5Dz0krENWL2oUYO5VoM78BTytmrFYB478= Received: by 10.50.34.201 with SMTP id b9mr6059060igj.6.1329883710046; Tue, 21 Feb 2012 20:08:30 -0800 (PST) X-BeenThere: rack-devel@googlegroups.com Received: by 10.50.131.138 with SMTP id om10ls49726igb.8.gmail; Tue, 21 Feb 2012 20:08:29 -0800 (PST) Received: by 10.50.168.68 with SMTP id zu4mr4814276igb.5.1329883709447; Tue, 21 Feb 2012 20:08:29 -0800 (PST) Received: by 10.50.203.103 with SMTP id kp7msigc; Tue, 21 Feb 2012 15:23:43 -0800 (PST) MIME-Version: 1.0 Received: by 10.236.114.170 with SMTP id c30mr3116513yhh.7.1329866622890; Tue, 21 Feb 2012 15:23:42 -0800 (PST) Received: by p13g2000yqd.googlegroups.com with HTTP; Tue, 21 Feb 2012 15:23:42 -0800 (PST) Date: Tue, 21 Feb 2012 15:23:42 -0800 (PST) User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.56 Safari/535.11,gzip(gfe) Message-ID: Subject: Rack streamed proxy causing Net::HTTPOK#read_body called twice From: Fabio Kreusch To: Rack Development X-Original-Sender: fabiokr@gmail.com X-Original-Authentication-Results: ls.google.com; spf=pass (google.com: domain of fabiokr@gmail.com designates internal as permitted sender) smtp.mail=fabiokr@gmail.com; dkim=pass header.i=@gmail.com Reply-To: rack-devel@googlegroups.com Precedence: list Mailing-list: list rack-devel@googlegroups.com; contact rack-devel+owners@googlegroups.com List-ID: X-Google-Group-Id: 486215384060 List-Post: , List-Help: , List-Archive: Sender: rack-devel@googlegroups.com List-Subscribe: , List-Unsubscribe: , Content-Type: text/plain; charset=ISO-8859-1 So, I have a Rack application which acts as a proxy. I have implemented a net/http api to deal with the communication, so the rack app basically calls it like this: api.new(request_method, rack_request, options).response .response returns a valid rack response [status, headers, body]. Body is an instance of the api, and it its implementation is like this (simplified version): def initialize ... @proxy_connection = Net::HTTP.start(proxied_uri.host, proxied_uri.port) @proxy_connection.request(@proxy_request) do |response| @proxy_response = response end end def each(&block) @proxy_response.read_body(&block) end def to_s @proxy_response.read_body end The rack app can then call the proxied service with a full response with to_s, or as a streaming and receive the response in chunks with each. The thing is, when I return the response in rack, I'm getting the following stack trace: https://gist.github.com/1879724 Apparently, the server or rack is calling 'each' more than once, but I'm not sure what might be causing it. The Rack app is running under rails 3.2.1.