From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on dcvr.yhbt.net X-Spam-Level: * X-Spam-ASN: AS33070 50.56.128.0/17 X-Spam-Status: No, score=1.0 required=3.0 tests=AWL,HK_RANDOM_FROM, MSGID_FROM_MTA_HEADER,TVD_RCVD_IP shortcircuit=no autolearn=no version=3.3.2 Path: news.gmane.org!not-for-mail From: Eric Wong Newsgroups: gmane.comp.lang.ruby.rainbows.general Subject: Re: negative timeout in Rainbows::Fiber::Base Date: Fri, 28 Sep 2012 19:24:49 +0000 Message-ID: <20120928192449.GB14292@dcvr.yhbt.net> References: <20120829211707.GA22726@dcvr.yhbt.net> <20120831013731.GA16613@dcvr.yhbt.net> <20120905232739.GA25153@dcvr.yhbt.net> <20120922194222.GA6839@dcvr.yhbt.net> <20120928191132.GA14292@dcvr.yhbt.net> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1348860305 14135 80.91.229.3 (28 Sep 2012 19:25:05 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 28 Sep 2012 19:25:05 +0000 (UTC) To: Rainbows! list Original-X-From: rainbows-talk-bounces-GrnCvJ7WPxnNLxjTenLetw@public.gmane.org Fri Sep 28 21:25:05 2012 Return-path: Envelope-to: gclrrg-rainbows-talk@m.gmane.org X-Original-To: rainbows-talk-GrnCvJ7WPxnNLxjTenLetw@public.gmane.org Delivered-To: rainbows-talk-GrnCvJ7WPxnNLxjTenLetw@public.gmane.org Content-Disposition: inline In-Reply-To: <20120928191132.GA14292-yBiyF41qdooeIZ0/mPfg9Q@public.gmane.org> User-Agent: Mutt/1.5.21 (2010-09-15) X-BeenThere: rainbows-talk-GrnCvJ7WPxnNLxjTenLetw@public.gmane.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: rainbows-talk-bounces-GrnCvJ7WPxnNLxjTenLetw@public.gmane.org Errors-To: rainbows-talk-bounces-GrnCvJ7WPxnNLxjTenLetw@public.gmane.org Xref: news.gmane.org gmane.comp.lang.ruby.rainbows.general:409 Archived-At: Received: from 50-56-192-79.static.cloud-ips.com ([50.56.192.79] helo=rubyforge.org) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1THgBM-0002YY-Oq for gclrrg-rainbows-talk@m.gmane.org; Fri, 28 Sep 2012 21:25:05 +0200 Received: from localhost.localdomain (localhost [127.0.0.1]) by rubyforge.org (Postfix) with ESMTP id 3CC2E2E06E; Fri, 28 Sep 2012 19:24:57 +0000 (UTC) Received: from dcvr.yhbt.net (dcvr.yhbt.net [64.71.152.64]) by rubyforge.org (Postfix) with ESMTP id 497D32E067 for ; Fri, 28 Sep 2012 19:24:49 +0000 (UTC) Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 52C101F42C; Fri, 28 Sep 2012 19:24:49 +0000 (UTC) Eric Wong wrote: > So the _actual_ Content-Length that's sent is zero? > > Rainbows! should drop a connection if an exception is raised while > sending the response body, perhaps the heroku router is confused > by that? Instead of trying "keepalive_timeout 0", you can also try using the following middleware. This only works for Content-Length responses (which seems to be your case) Of course, like all middleware, this makes your stack deeper, so maybe it's not good, either... Furthermore, this code is totally untested, it may not even compile, but I hope you get the idea and fix trivial errors :) class PadOnError def initialize(app) @app = app end def call(env) status, headers, body = @app.call(env) headers = Rack::Utils::HeaderHash.new(headers) clen = headers["Content-Length"] if clen [ status, headers, Padder.new(clen.to_i, body) ] else # TODO: write your own Transfer-Encoding: chunked padder :) # It would need to parse the chunked encoding and keep track # of each chunk length, pad any unfinished chunk, and ensure # termination with "0\r\n\r\n" [ status, headers, body ] end end class Padder def initialize(clen, body) @clen = clen @body = body @bytes_sent = 0 end def each @body.each do |chunk| @bytes_sent += chunk.bytesize # if this raises due to a socket error... we'll just end up # raising (again) below yield chunk end ensure # pad the response in case @body.each raised an error while # generating. left_to_send = clen - @bytes_sent # XXX assuming you're sending HTTP responses that fit comfortably in # memory, this can OOM if you're sending multi-mega/gigabyte files # like most of my applications :P if left_to_send > 0 padding = " " * left_to_send yield padding end end def close @body.close if @body.respond_to?(:close) end end end ----------------------- config.ru ------------------------ use PadOnError run YourApp.new --------------------------------------------------------- _______________________________________________ Rainbows! mailing list - rainbows-talk-GrnCvJ7WPxnNLxjTenLetw@public.gmane.org http://rubyforge.org/mailman/listinfo/rainbows-talk Do not quote signatures (like this one) or top post when replying