Zbatery/Rainbows keepalive problem?

Eric Wong normalperson at yhbt.net
Wed Nov 24 17:14:02 EST 2010

Jake Douglas <jakecdouglas at gmail.com> wrote:
> On Wed, Nov 24, 2010 at 1:17 PM, Eric Wong <normalperson at yhbt.net> wrote:
> > Jake Douglas <jakecdouglas at gmail.com> wrote:
> >> I am using zbatery with ThreadPool and just upgraded to 0.5.0, which
> >> subsequently upgraded rainbows to 2.0.0 and unicorn to 3.0.0. My
> >> browser(s) now hangs for a while during each request. I noticed some
> >
> > Are you setting a Content-Length or Transfer-Encoding in your app?
> >
> > You can add Rack::Chunked and Rack::ContentLength middlewares to your
> > config (some frameworks like Rails already do this, I think).
> >
> > Which versions of Zbatery/Rainbows!/Unicorn were you using before which
> > exhibited this?  Rainbows!/Zbatery has supported keepalive for some time
> > and none of the three servers ever included
> > Rack::Chunked/Rack::ContentLength in its middleware stack by default.
> I was using zbatery 0.4.0, Unicorn 2.0.1, unsure of the rainbows
> version. This is a Rails 3.0.3 app and I am not setting any headers
> myself. Are you saying that Rails is doing something that is causing
> the problem? Please bear with me, as I am not familiar with the
> details of how keep alive works.

<top posting corrected>

Responses without keepalive don't need additional headers since the
server just closes the connection to notify the client.

HTTP/1.1 with keepalive requires a Content-Length (or Transfer-Encoding:
chunked) header to determine response boundaries, otherwise clients
would never know when one response ends and another begins.

The normal Rails "render" path already seems[1] to add Content-Length;
are you doing something else to send responses from Rails?

Including the Rack::Chunked/Rack::ContentLength middlewares (at the top
of the middleware stack) should solve all your problems.

If you only serve HTTP/1.1, you can probably get away with only

[1] - I haven't had a chance to test this myself

Eric Wong

More information about the rainbows-talk mailing list