This project is archived and is in readonly mode.

#6026 open
Doug Mayer

[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

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>

Attachments

Tags

Pages