Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

[PATCH] response_body proc is called twice

#6026

When you set the response_body to a proc, it will be called twice: first during the normal execution, and a second time by Rack::Response#close. Martin Gogov noted this in #4554 render :text => proc { ... } regression and I believe this is related (but not the same issue).

The relevant Rack::Response code is (http://github.com/rack/rack/blob/master/lib/rack/response.rb#L102-104):

def close
  body.close if body.respond_to?(:close)
end

This patch just adds a close method to ActionDispatch::Response which will delegate it to @body instead of #body, avoiding the double call of the proc.

Putting a breakpoint inside my proc shows the following stacktraces... The first time:

(rdb:4) w --> #0 ActionDispatch::Response.each

   at line /Users/doug/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.3/lib/action_dispatch/http/response.rb:35
[#1](/projects/8994/tickets/1 "Ticket #1") ActionDispatch::Response.each 
   at line /Users/doug/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.3/lib/action_dispatch/http/response.rb:152
[#2](/projects/8994/tickets/2 "Ticket #2") Rack::Handler::WEBrick.service(req#WEBrick::HTTPRequest, res#WEBrick::HTTPResponse,...) 
   at line /Users/doug/.rvm/gems/ruby-1.9.2-p0/gems/rack-1.2.1/lib/rack/handler/webrick.rb:64
[#3](/projects/8994/tickets/3 "Ticket #3") WEBrick::HTTPServer.service(req#WEBrick::HTTPRequest, res#WEBrick::HTTPResponse,...) 
   at line /Users/doug/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/webrick/httpserver.rb:111
[#4](/projects/8994/tickets/4 "Ticket #4") WEBrick::HTTPServer.run(sock#TCPSocket) 
   at line /Users/doug/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/webrick/httpserver.rb:70
[#5](/projects/8994/tickets/5 "Ticket #5") at line /Users/doug/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/webrick/server.rb:183

And the second time:

(rdb:4) w --> #0 ActionDispatch::Response.each

   at line /Users/doug/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.3/lib/action_dispatch/http/response.rb:35
[#1](/projects/8994/tickets/1 "Ticket #1") ActionDispatch::Response.each 
   at line /Users/doug/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.3/lib/action_dispatch/http/response.rb:152
[#2](/projects/8994/tickets/2 "Ticket #2") ActionDispatch::Response.body 
   at line /Users/doug/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.3/lib/action_dispatch/http/response.rb:101
[#3](/projects/8994/tickets/3 "Ticket #3") Rack::Response.close 
   at line /Users/doug/.rvm/gems/ruby-1.9.2-p0/gems/rack-1.2.1/lib/rack/response.rb:102
[#4](/projects/8994/tickets/4 "Ticket #4") Rack::Handler::WEBrick.service(req#WEBrick::HTTPRequest, res#WEBrick::HTTPResponse,...) 
   at line /Users/doug/.rvm/gems/ruby-1.9.2-p0/gems/rack-1.2.1/lib/rack/handler/webrick.rb:68
[#5](/projects/8994/tickets/5 "Ticket #5") WEBrick::HTTPServer.service(req#WEBrick::HTTPRequest, res#WEBrick::HTTPResponse,...) 
   at line /Users/doug/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/webrick/httpserver.rb:111
[#6](/projects/8994/tickets/6 "Ticket #6") WEBrick::HTTPServer.run(sock#TCPSocket) 
   at line /Users/doug/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/webrick/httpserver.rb:70
[#7](/projects/8994/tickets/7 "Ticket #7") at line /Users/doug/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/webrick/server.rb:183

Reported by Doug Mayer · November 21st, 2010 @ 09:38 AM

State: open
Milestone: 3.0.6
Assigned to: Santiago Pastorino Santiago Pastorino
Importance: Low

Activity

  1. Doug Mayer
  2. Doug Mayer
  3. rails
    rails
    • 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.

    February 22nd, 2011 @ 12:00 AM

  4. rails
    rails
    • State changed from open to stale

    February 22nd, 2011 @ 12:00 AM

  5. Doug Mayer
    Doug Mayer

    Please don't close this! It is still a relevant issue.

    February 22nd, 2011 @ 01:37 AM

  6. naruse
    naruse

    I also hit this problem; this is still happen.

    March 30th, 2011 @ 03:35 AM

  7. Doug Mayer
    Doug Mayer

    @naruse: Are you able to try out my patch at all? I'm not sure how to get more traction on having it applied. :-/

    April 1st, 2011 @ 04:11 PM

  8. naruse
    naruse

    @mayer: I confirmed your patch fixes this problem, thanks.

    So I want Rails 3.0.6 merge this patch.

    April 5th, 2011 @ 02:01 AM

  9. Doug Mayer
    Doug Mayer
    • Assigned user set to Santiago Pastorino

    It looks like this may be your domain, Santiago. Any chance we could get it in Rails proper soon?

    April 20th, 2011 @ 04:21 AM

  10. Mark Borcherding
    Mark Borcherding

    The patch worked for me as well.

    April 20th, 2011 @ 04:24 AM

  11. Santiago Pastorino
    Santiago Pastorino
    • State changed from stale to open
    • Milestone set to 3.0.6
    • Importance changed from to Low

    April 24th, 2011 @ 09:57 PM

  12. Santiago Pastorino
    Santiago Pastorino

    Hey guys can you provide a test with the fix. I will merge it. Thanks

    May 4th, 2011 @ 07:45 PM