This project is archived and is in readonly mode.

#2993 ✓ resolved
Adam Milligan

First request will always have an empty body due to delayed load of action_controller/cgi_process

Reported by Adam Milligan | August 4th, 2009 @ 08:06 AM | in 2.3.6

After you restart a Mongrel server the first request will always fail to have the correct HTTP request body. The reason for this is the override of CGI#initialize_query method by ActionController in the cgi_ext/query_extension.rb file.

Specifically, the overridden function does not read from the IO stream representing the request body, while the original method does. This means the original method leaves the read pointer at the end of the buffer, so any subsequent reads return nothing.

The problem arrises on server restart because loading the Rails environment doesn't preload the cgi_ext.rb or cgi_ext/*.rb files by default. The query_extension.rb file doesn't load until after the first request body has been processed, so for that first request the original method gets invoked, and the request appears to have no body.

This isn't generally a problem for web sites, since the first request is nearly invariably a GET request with an empty body (for the homepage). However, for a web service, if the first request after a server restart or environment reload is a POST or PUT, then that request will fail, and fail messily.

I realize everything CGI has been deprecated, which is why I haven't provided a patch, but I don't really know how long this could be a problem. I'm curious to hear if this won't be a problem going forward (i.e. as of 2.3.4), or if it should be patched. Finding the problem was a challenge, but the solution is easy: just require action_controller/cgi_ext.rb when ActionController loads.

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

Tickets have moved to Github

The new ticket tracker is available at https://github.com/rails/rails/issues

Shared Ticket Bins

Attachments

Referenced by

Pages