New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Puma 6.2 does not respond correctly when Rails app responds with empty body #3112
Comments
head(:not_found)
head(:not_found)
I'm also experiencing this. I've narrowed it down to any response (regardless of status code) that returns an empty body. You can work around it by doing something like |
head(:not_found)
I'm looking at this, not sure if it's a bug in Rails. The Rack spec states: The Body must respond to A Body that responds to both I'm trying to figure out what Rails is returning for the body... |
I'm not sure though, how and where a processed |
Thanks. I also got that far, but then interrupted. Can you test locally with a patch or a different branch? I tried locally with a 'rackup' file with various bodies, and it seems to be working correctly, but Rails wraps the body with a bit of code, depending on the setup... |
I can try. I'm currently not at my workstation anymore though, so response times (heh...) might be sluggish. |
In a Pry session, I've stepped up around two dozen caller frames to this point (the first/last Puma method):
Skipping
Does this help? |
Thank you. Yes, that helps. I was going to try a |
Can you try replacing: Line 183 in 52fa8f6
with:
That fixes an issue if the body is |
That doesn't help, |
That seems to be the default value, |
In case it helps, here's the view from telnet (shows exactly what the response looks like, unlike that weird curl error):
That |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, AFK for a bit
So, we have: if res_body.respond_to?(:to_ary) && (array_body = res_body.to_ary) &&
array_body.is_a?(Array)
body = array_body.compact
content_length = body.sum(&:bytesize)
elsif res_body.is_a?(File) && res_body.respond_to?(:size)
body = res_body
content_length = body.size
elsif res_body.respond_to?(:to_path) && File.readable?(fn = res_body.to_path)
body = File.open fn, 'rb'
content_length = body.size
close_body = true
else
body = res_body
end If I've got to determine how this response body is traversing the logic... |
Breakpoint just before the condition: content_length
#=> nil
resp_info
#=> {:no_body=>nil, :allow_chunked=>true, :keep_alive=>true, :response_hijack=>nil}
res_body.respond_to?(:to_ary)
#=> true
array_body = res_body.to_ary
#=> nil
array_body.is_a?(Array)
#=> false None of the conditionals match, and the |
Um... |
Thanks. I think it was removed in 7.0, but master currently has def to_ary
@buf.to_ary
end Or, this can get really fun. Regardless, I'm wading thru it. I don't have the code memorized, and without content-length, it's hard to determine whether the body needs to be chunked... |
#3113 seems to fix this issue. |
Copying desc from my PR here for visibility:
Probably needs a unit test, but I have yet to grok the test coverage that Puma has or how to write this one... will take me a while. |
If you'd like to, but I've already got a test for it, or at least an app response for it. I'll post in your PR. |
Definitely would appreciate help writing the test(s)! |
Describe the bug
In one of my Rails 6.1 apps, I have code that boils down to:
With Puma 6.1.1 I get the following response:
curl
Rails log
After upgrading to Puma 6.2, this is the result:
curl
Rails log
When pointing Firefox to http://localhost:3000/thing, the browser hangs for 20s, then prints a 0.
I've captured the network traffic: puma.pcap.gz
Puma config:
config/puma.rb
This is the unaltered config file generated by
rails new
:The Rails app is started with
bundle exec rails server -b '::'
.To Reproduce
I've prepared a repro-repo. You'll need Ruby 3.0.5:
To switch to Puma 6.2:
Expected behavior
head(:not_found)
should work as expected.Desktop (please complete the following information):
The text was updated successfully, but these errors were encountered: