This project is archived and is in readonly mode.
[PATCH] response_body proc is called twice
Reported by Doug Mayer | November 21st, 2010 @ 09:38 AM | in 3.0.6
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 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
Comments and changes to this ticket
-
Doug Mayer November 21st, 2010 @ 09:45 AM
- no changes were found...
-
Doug Mayer November 21st, 2010 @ 06:36 PM
- Tag set to patch
-
rails February 22nd, 2011 @ 12:00 AM
- 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.
-
rails February 22nd, 2011 @ 12:00 AM
- State changed from open to stale
-
Doug Mayer April 1st, 2011 @ 04:11 PM
@naruse: Are you able to try out my patch at all? I'm not sure how to get more traction on having it applied. :-/
-
naruse April 5th, 2011 @ 02:01 AM
@mayer: I confirmed your patch fixes this problem, thanks.
So I want Rails 3.0.6 merge this patch.
-
Doug Mayer April 20th, 2011 @ 04:21 AM
- 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?
-
Santiago Pastorino April 24th, 2011 @ 09:57 PM
- State changed from stale to open
- Milestone set to 3.0.6
- Importance changed from to Low
-
Santiago Pastorino May 4th, 2011 @ 07:45 PM
Hey guys can you provide a test with the fix. I will merge it. Thanks
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>