This project is archived and is in readonly mode.
rack.input already read on first upload to a Rails Metal in production
Reported by maschnitz (at yahoo) | April 5th, 2009 @ 09:08 PM | in 3.x
rack.input is being read or seeked through improperly before I touch it. It's only upon the first upload to each of my mongrel cluster's servers. The mongrel server is fronted by Apache mod_proxy_balancer.
Steps to reproduce:
1) Set up a basic Rails app, with a mongrel_cluster and Apache mod_proxy_balancer front end.
2) Create a new Metal, app/metal/test.rb with:
require(File.dirname(__FILE__) + "/../../config/environment") unless defined?(Rails)
class Test
def self.call(env)
if env["PATH_INFO"] =~ /^\/test/i
req = Rack::Request.new(env)
if req.post?
return [200, {"Content-Type" => "text/html"}, [env['rack.input'].pos.to_s]]
else
return [200, {"Content-Type" => "text/html"}, [ %Q|
<form enctype="multipart/form-data" id="post_form" method="post">
<input id="file" name="file" size="30" type="file">
<input id="submit" name="commit" value="submit" type="submit">
</form>
| ]]
end
else
[404, {"Content-Type" => "text/html"}, ["Not Found"]]
end
end
end
3) Run the app, and navigate to /test.
4) Upload a file. Note the seek position reported. It is not zero. Instead, in my tests, it's the end of the StringIO.
5) Repeat the upload N times, where N is the number of mongrel servers in your cluster. (Assuming a round-robin or load-based proxy. Other proxy methods might require less.)
6) On the Nth try, the seek position has gone to 0. I believe this is the proper value.
Note that this does not happen in development mode, under an unproxied Rails rackup server, nor an unproxied mongrel server. I have not tried a rackup with just this Metal (not familiar enough with it).
The workaround is simple: call env['rack.input'].rewind before doing anything else in the Metal.
Versions: - Rails 2.3.2 - Rack 0.9.1 - Ruby 1.8.6 - Mongrel 1.1.5 - Apache 2.2.9 - Ubuntu 8.10
I'm not sure which subsystem is doing this. Please let me know if this is mongrel's or rack's problem.
Comments and changes to this ticket
-
Wilson Bilkovich April 14th, 2009 @ 08:26 PM
mongrel_cluster interfaces with Rack in CGI mode. Inside Mongrel, the first request appears to leave the request body StringIO positioned at the end of the data stream.
Since that part of mongrel (lib/mongrel/cgi.rb) is only necessary in that mode, you don't see the problem when you use rackup, etc.
The fix to Mongrel is a one-liner, but I still need to track down why only the first request suffers from this.
-
Santiago Pastorino February 2nd, 2011 @ 04:50 PM
- State changed from new to open
This issue has been automatically marked as stale because it has not been commented on for at least three months.
The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.
Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.
-
Santiago Pastorino February 2nd, 2011 @ 04:50 PM
- State changed from open to stale
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>