This project is archived and is in readonly mode.
Rails 2.3.x - "render :text => proc" - problems with output buffer
-
Michael Koziarski
- Tag changed from 2-3-stable, 2.3.2, render to 2-3-stable, 2.3.2, bugmash, render
-
Nikolay Petrachkov
- Assigned user set to CancelProfileIsBroken
Code above throw error:
Internal Server Error
undefined method `flush' for #<ActionController::Response:0x00000002bf4300>ActionController::Response doesn't contain method response .
Without output.flush code works:
curl http://localhost:3000/lines/show This is line 0 This is line 1 This is line 2 This is line 3 This is line 4 This is line 5 This is line 6 This is line 7 This is line 8 This is line 9
-
CancelProfileIsBroken
- Assigned user changed from CancelProfileIsBroken to Michael Koziarski
-
Nick Quaranto
Verified with 2-3-stable, used the same example and it breaks with both a proc and lambda.
2893 master % curl http://localhost:3000/lines/show This is line 0 curl: (18) transfer closed with outstanding read data remainingProcessing LinesController#show (for 127.0.0.1 at 2009-08-08 10:39:05) [GET] Completed in 3ms (View: 1, DB: 0) | 200 OK [http://localhost/lines/show] Sat Aug 08 10:39:05 -0400 2009: Read error: #<NoMethodError: undefined method `flush' for #<ActionController::Response:0x2915b34>> /Users/qrush/Dev/bugmash/2893/app/controllers/lines_controller.rb:8:in `show' /Users/qrush/Dev/bugmash/2893/app/controllers/lines_controller.rb:6:in `times' /Users/qrush/Dev/bugmash/2893/app/controllers/lines_controller.rb:6:in `show' /Users/qrush/Dev/bugmash/2893/vendor/rails/actionpack/lib/action_controller/response.rb:153:in `call' /Users/qrush/Dev/bugmash/2893/vendor/rails/actionpack/lib/action_controller/response.rb:153:in `each' /Users/qrush/Dev/bugmash/2893/vendor/rails/actionpack/lib/action_controller/reloader.rb:21:in `send' /Users/qrush/Dev/bugmash/2893/vendor/rails/actionpack/lib/action_controller/reloader.rb:21:in `method_missing' /opt/local/lib/ruby/gems/1.8/gems/rack-1.0.0/lib/rack/chunked.rb:37:in `each' /opt/local/lib/ruby/gems/1.8/gems/rack-1.0.0/lib/rack/handler/mongrel.rb:74:in `process' /opt/local/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:159:in `process_client' /opt/local/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:158:in `each' /opt/local/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:158:in `process_client' /opt/local/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:285:in `run' /opt/local/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:285:in `initialize' /opt/local/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:285:in `new' /opt/local/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:285:in `run' /opt/local/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:268:in `initialize' /opt/local/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:268:in `new' /opt/local/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:268:in `run' /opt/local/lib/ruby/gems/1.8/gems/rack-1.0.0/lib/rack/handler/mongrel.rb:34:in `run' /Users/qrush/Dev/bugmash/2893/vendor/rails/railties/lib/commands/server.rb:111 /opt/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require' /opt/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require' script/server:3This definitely works with 2-2-stable for me as well:
2893 master % curl http://localhost:3000/lines/show This is line 0 This is line 1 This is line 2 This is line 3 This is line 4 This is line 5 This is line 6 This is line 7 This is line 8 This is line 9 -
Josh Nichols
Verified, as I was watching over Nick's shoulder.
-
Nick Quaranto
Looks like ActionController already supports this. From actionpack/test/controller/rack_test.rb:
def test_streaming_block @response.body = Proc.new do |response, output| 5.times { |n| output.write(n) } end @response.prepare! status, headers, body = @response.to_a assert_equal 200, status assert_equal({ "Content-Type" => "text/html; charset=utf-8", "Cache-Control" => "no-cache", "Set-Cookie" => "" }, headers) parts = [] body.each { |part| parts << part } assert_equal ["0", "1", "2", "3", "4"], parts endJosh and I have prepared a patch that implements flush on ActionController::Response and warns the user about this.
-
Josh Nichols
+1 on the patch. It giving a deprecation warning seems the most reasonable, since chunking already happens without it, so just warning will give the user a heads up that they can safely remove it.
-
Pratik
Adding Yehuda to notifications.
-
Nikolay Petrachkov
+1 Patch works.
-
Nick Quaranto
Looks like this is an issue with Rails 3.0 as well, and since the Response class is now under ActionDispatch it needed a new patch. Here's patches for both 2-3-stable and master.
-
Dan Croak
+1 confirmed test and patch apply in both 2-3-stable and master (rake test_action_pack is clean in both branches)
-
Dan Pickett
+1 and I verified Nick's patch applies cleanly to master - patch applies and suite passes
-
Jeremy Kemper
- State changed from new to open
- Milestone changed from 2.x to 2.3.4
Could you update the docs to omit the flush call?
Then only 2-3-stable needs the deprecation warning and master is fine as-is.
-
Nick Quaranto
Removed the flush call from the docs.
-
Jeremy Kemper
- State changed from open to committed
- Tag changed from 2-3-stable, 2.3.2, bugmash, render to 2-3-stable, 2.3.2, render
2-3-stable: d39c45690e501e7572de2f70f68224bc95e6bf01
-
JDL
Thank you very much to everyone who worked on this. I really appreciate it.
-
Repository
(from [d39c45690e501e7572de2f70f68224bc95e6bf01]) Adding a deprecation warning for output.flush when rendering a proc or lambda
[#2893 Rails 2.3.x - "render :text => proc" - problems with output buffer state:committed]
Signed-off-by: Jeremy Kemper jeremy@bitsweat.net
http://github.com/rails/rails/commit/d39c45690e501e7572de2f70f68224...
