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
lowlevel_error_handler is unexpectedly invoked when an HTTP/1.1 client closes its connection first #2390
Comments
The error reported to the
|
@schneems I think the problem is that the I tried to write a test to reproduce the behavior (without just calling |
Just thinking aloud for a moment - we don't want to report this to lowlevel_error_handler because we're saying this the client's fault, and lowlevel_error_handler is only for exceptional circumstances where Puma fumbles? |
I've got this issue showing up in a way that we can use in test. But, if you add |
Yeah, I think it's a good idea to take a step back and make sure we're intentional about implementing the behavior we want instead of just blindly making puma do what it did before. I think you are basically right in this case--though I wouldn't really assign blame to the client since I think the behavior isn't really a violation of the spec. RFC 7230 describes the behavior of HTTP connection persistence
So since
So I think With regard to whether or not
There are some places where the |
Nope. If I add |
Perfect. That makes sense to me, I agree this is a regression. |
I copied some methods from the test suite, when I bypassed those, I only had one request logged. Sorry. Got to figure out what did that... Anyway, the following might be a fix: lib/puma/reactor.rb | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/lib/puma/reactor.rb b/lib/puma/reactor.rb
index 2941bea0e..bbc40ee49 100644
--- a/lib/puma/reactor.rb
+++ b/lib/puma/reactor.rb
@@ -254,9 +254,10 @@ def run_internal
@events.parse_error e, c
rescue StandardError => e
- @server.lowlevel_error(e, c.env)
-
- c.write_error(500)
+ unless EOFError === e # assume client closed connection
+ @server.lowlevel_error(e, c.env)
+ c.write_error(500)
+ end
c.close
clear_monitor mon |
That would work, but the comment up above with diff --git a/lib/puma/reactor.rb b/lib/puma/reactor.rb
index 2941bea0..b1341358 100644
--- a/lib/puma/reactor.rb
+++ b/lib/puma/reactor.rb
@@ -229,7 +229,7 @@ module Puma
# Don't report these to the lowlevel_error handler, otherwise
# will be flooding them with errors when persistent connections
# are closed.
- rescue ConnectionError
+ rescue EOFError, ConnectionError
c.write_error(500)
c.close
|
Duh. LGTM. One thing though, EOFError means it's closed, but |
Oh yeah that's interesting. You'd think that if we got a But inside The Reactor relied on this same behavior before #2384, but it is weird that any of it worked at all. I guess maybe |
Along with watching the wonderful debate, I worked some more with this, and hitting Puma with a browser also logged errors. Not good. I'll work on a test tomorrow, but the fix works... |
Slapping |
Pretty sure this issue has been resolved by #2279 (which refactored the error-reporting behavior into |
Confirmed that @wjordan is correct. I've got a test I can add, fails with 5.0.2, passes with master. |
Describe the bug
If a client opens a TCP connection, writes a HTTP/1.1 request (without explicitly specifying a
Connection: close
header or anything like that), reads the response, then closes the TCP connection, then puma unexpectedly invokes thelowlevel_error_handler
. I think this is a regression introduced in 5.0.1, possibly by #2384.Puma config:
bundle exec ruby -Ilib bin/puma -C test/config/lowlevel_test.rb
To Reproduce
Expected behavior
The lowlevel handler isn't invoked, consistent with the behavior of puma v5.0.0
Desktop (please complete the following information):
The text was updated successfully, but these errors were encountered: