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
Always send lowlevel_error response to client #2731
Conversation
@@ -45,15 +45,15 @@ def test_integer_key | |||
server_run app: ->(env) { [200, { 1 => 'Boo'}, []] } | |||
data = send_http_and_read "GET / HTTP/1.0\r\n\r\n" | |||
|
|||
assert_match(/HTTP\/1.1 500 Internal Server Error/, data) | |||
assert_match(/HTTP\/1.0 500 Internal Server Error/, data) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did this have to change? Looks like something isn't working now? This is the failure without this change:
Errors & Failures:
1) Failure:
TestResponseHeader#test_integer_key [test/test_response_header.rb:48]:
Expected /HTTP\/1.1 500 Internal Server Error/ to match # encoding: ASCII-8BIT
# valid: true
"HTTP/1.0 200 OK\r\nHTTP/1.0 500 Internal Server Error\r\nContent-Length: 559\r\n\r\nPuma caught this error: undefined method `downcase' for 1:Integer (NoMethodError)\n/Users/dentarg/src/puma/lib/puma/request.rb:437:in `block in str_headers'\n/Users/dentarg/src/puma/lib/puma/request.rb:434:in `each'\n/Users/dentarg/src/puma/lib/puma/request.rb:434:in `str_headers'\n/Users/dentarg/src/puma/lib/puma/request.rb:122:in `write_response'\n/Users/dentarg/src/puma/lib/puma/request.rb:97:in `handle_request'\n/Users/dentarg/src/puma/lib/puma/server.rb:447:in `process_client'\n/Users/dentarg/src/puma/lib/puma/thread_pool.rb:147:in `block in spawn_thread'".
If I make the assert fail on master it looks like
Run options: --verbose --name /test_integer_key/ --seed 19438
# Running:
TestResponseHeader#test_integer_key = 0.02 s = F
Fabulous run in 0.024515s, 40.7914 runs/s, 81.5827 assertions/s.
Errors & Failures:
1) Failure:
TestResponseHeader#test_integer_key [test/test_response_header.rb:48]:
Expected /aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/ to match # encoding: ASCII-8BIT
# valid: true
"HTTP/1.1 500 Internal Server Error\r\n\r\n".
1 runs, 2 assertions, 1 failures, 0 errors, 0 skips
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess it is coming from this code and the fact that @leak_stack_on_error
is true in test and development
Lines 543 to 548 in 7812f1b
if @leak_stack_on_error | |
backtrace = e.backtrace.nil? ? '<no backtrace available>' : e.backtrace.join("\n") | |
[status, {}, ["Puma caught this error: #{e.message} (#{e.class})\n#{backtrace}"]] | |
else | |
[status, {}, ["An unhandled lowlevel error occurred. The application logs may have details.\n"]] | |
end |
Maybe it has "always" been like this... but the start with HTTP/1.0 200 OK\r\n
looks strange?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not entirely sure, but the spec send a HTTP 1.0 request so I think it makes sense it gets a HTTP 1.0 response back. Maybe something was off before :) ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it was hard coded before: https://github.com/baelter/puma/blob/a2bcda414377ee3f5855a66ed83aa41ce6f0a29d/lib/puma/const.rb#L139
But now we use the correct version.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's been a change though, this tests triggers an exception in str_headers
and if we look at str_headers
it has already populated the buffer with a 200 response, that is also included when we try write the error response with write_response
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, nice catch
228d4a3
to
388141a
Compare
388141a
to
40c72f9
Compare
Thank you for trying to close such a long-standing issue! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome work!
Changes look good to me. If it looks good to you guys @nateberkopec and @dentarg , I think we're good to merge. |
I should disclose that @baelter is my co-worker at 84codes, hence I was quick to look at this one. I think a second approve from someone else would be great, maybe @MSP-Greg if @nateberkopec doesn't have the time right now? |
Thanks! |
* Always send lowlevel_error response to client * Add spec for lowlever error handler * Make sure we have a clean buffer when starting response * Simplify test * Rename spec * Add method docs * Tweak the test * Return 500 from lowlevel_error_handler in test Co-authored-by: Patrik Ragnarsson <patrik@starkast.net>
Description
Always send what the lowlevel_error handler returns to the client.
Refactors some code out of
Request#handle_request
to a newRequest#write_response
that can be used fromServer
to send the response fromlowlevel_error
Closes #2341
Your checklist for this pull request
[ci skip]
to the title of the PR.#issue
" to the PR description or my commit messages.