[Mongrel] [ANN] Mongrel 1.0 RC1 Full Win32 Build

Zed A. Shaw zedshaw at zedshaw.com
Wed Dec 20 10:12:50 EST 2006

On Wed, 20 Dec 2006 11:06:46 +0000
Jonathan del Strother <maillist at steelskies.com> wrote:

> On 20 Dec 2006, at 10:02, Zed A. Shaw wrote:
> > On Tue, 19 Dec 2006 23:44:03 -0500
> > "Michael D'Auria" <michael.dauria at gmail.com> wrote:
> >
> >> Hey Zed,
> >>
> >> I'm excited for Mongrel 1.0 final!  I do have something i ran into  
> >> before
> >> and still is occurring with the new version.  When i run into a  
> >> 500 based
> >> error i seem to get header information as output when using mongrel:
> > <snip>
> >>
> >> I still get the appropriate page as i should, i just get the  
> >> header info
> >> before the page output.  I remember you telling me that Rails is  
> >> sending
> >> back the error and page this way, but is there something that can  
> >> be done so
> >> this is not shown?
> >
> > Yeah, there's not much I can do about it right now without changing  
> > how rails works and generates its error reports.  I tried to crack  
> > it again when DHH complained but it just would take way too much  
> > rewriting to fix the rewriting. :-)
> >
> > The plan is to tackle that problem and a host of others in later  
> > versions.
> I can't seem to find any previous discussion on this in the archives  
> - could you give us a quick rundown on what the cause is?

In order to get headers and the body out Mongrel has to split the IO in two and the case of Rails fake the cgi.rb stuff out with StringIO objects.  The problem is that Rails (and other frameworks) like to mix up header and body production so everything is out of order.  Since an HTTP response has headers first then the body, I have to collect the headers in one StringIO, the body in a second, and then after Rails is done, send this out later.

Everything works fine until Rails has a catastrophic error that causes your "500 page of death".  In this case there was already some headers and some body sent out but the error caused Rails to try to "reset" the output and send something totally different, the 500 page.  When it does this reset, the headers get screwed up and the body shows some of the headers.

Fixing it would require changing how rails does it's 500 error reporting, or potentially dropping it for an alternative.  A simple fix would be to have Rails do a special Mongrel call that tells Mongrel the request failed and Mongrel could produce the 500 page, but then that'd alienate the other methods for deploying rails.  Another solution is to rewrite all the carefully tuned Mongrel output processing so that it handles this by buffering everything and writing nothing anywhere until it's really really final.

Since Rails is pushing for 1.2, Mongrel is pushing for 1.0, and having a nasty looking 500 page isn't the end of the world, I'm just punting until later.

Zed A. Shaw, MUDCRAP-CE Master Black Belt Sifu
http://www.awprofessional.com/title/0321483502 -- The Mongrel Book
http://www.lingr.com/room/3yXhqKbfPy8 -- Come get help.

More information about the Mongrel-users mailing list