Rewindable rack input

67 views
Skip to first unread message

Saimon Moore

unread,
Mar 12, 2009, 8:23:37 PM3/12/09
to CloudKit
Hi Jon,

I'm giving cloudkit a spin (using version 0.11.0) and I've come up
with a problem when using passenger (passenger-2.1.1 beta) to serve
the rack app. (i.e. the bug doesn't appear with mongrel)

I've tentatively tracked this down to Request#json and in particular
sending the #rewind message to the request body (i.e rack input).
For whatever reason, using mongrel the body was an instance of
Rack::Lint::InputWrapper. Using passenger, it was an instance of
TCPSocket which doesn't have a #rewind message.

My solution was to see how rails 2.3 handled this problem. Josh Peek
wrote a rewindable_input middleware which basically wraps rack input
in a StringIO to ensure it's rewindable. Using this middleware => no
more exception.

See code here:
http://gist.github.com/78368

I'm not sure where the actual fault lies (This could be a bug in
passenger) but perhaps you want to investigate further....

Regards,

Saimon

Jon Crosby

unread,
Mar 13, 2009, 4:51:20 PM3/13/09
to clou...@googlegroups.com
On Thu, Mar 12, 2009 at 5:23 PM, Saimon Moore <saimo...@gmail.com> wrote:

Hi Jon,

I'm giving cloudkit a spin (using version 0.11.0) and I've come up
with a problem when using passenger (passenger-2.1.1 beta) to serve
the rack app. (i.e. the bug doesn't appear with mongrel)

I've tentatively tracked this down to Request#json and in particular
sending the #rewind message to the request body (i.e rack input).
For whatever reason, using mongrel the body was an instance of
Rack::Lint::InputWrapper. Using passenger, it was an instance of
TCPSocket which doesn't have a #rewind message.

Saimon, thank you for tracking this down and bringing it up on the list. If passenger is setting rack.input to something that does not respond to #rewind, then it is violating the spec for Rack. That being the case, I like the pragmatic solution that you provided, wrapping the input so that it is rewindable in all cases. I'll do some experiments with Passenger just to confirm this and if everything checks out, a patch for CloudKit may be in order. 

Ryan Garver

unread,
Apr 6, 2009, 7:53:52 PM4/6/09
to CloudKit
Thanks Saimon, this helped me out a lot. I'm using cloudkit 0.11.1
and passenger 2.1.3. This problem originally revealed itself as a
"Premature end of script headers" error in the apache logs, but
eventually I arrived at your conclusion that the issue was with
#rewind. Looking forward to an official fix on this from cloudkit or
passenger, whoever wants the honor ;)

On Mar 13, 1:51 pm, Jon Crosby <jon.r.cro...@gmail.com> wrote:

Jon Crosby

unread,
Apr 12, 2009, 6:26:02 PM4/12/09
to clou...@googlegroups.com
The issue of Passenger and Rack is being discussed in detail on the
Rack list now:

http://groups.google.com/group/rack-devel/browse_thread/thread/4324acc264d9d6ed

Let's keep an eye on that thread for a few days and see where it goes.
If a solution is not implemented, we can go with the Rails fix for
now.

-Jon
Reply all
Reply to author
Forward
0 new messages