From dfd198d92672dfce704310dc6bf4a39dcbfa9e36 Mon Sep 17 00:00:00 2001 From: schneems Date: Fri, 25 Sep 2020 09:56:58 -0500 Subject: [PATCH] [close #2371] Do not log EOFError This is a continuation from #2382. One of the ways that an EOFError can be triggered is by opening a connection, not writing to it, then closing it (there may be others). This should be an expected and non-exceptional activity. When it happens we should not log it. This commit gets the test in the prior commit to pass. The change to client.rb makes sense to me as this is the initial place where we're reading from the socket and then finding out the stream has been closed. Im not quite sure why the code in server.rb is needed. I think this comes from when the server is shutting down and trying to finish out connections. I don't think this is the 100% right way to do things. I'm guessing that if we get an EOFError on a connection we should somehow consider it "dead" and never try to read from it again. I don't know if there's a better way to signify this in the `try_to_finish` method of client.rb --- History.md | 1 + lib/puma/client.rb | 4 +++- lib/puma/server.rb | 6 +++++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/History.md b/History.md index 3dd886937a..e5ef9e60ab 100644 --- a/History.md +++ b/History.md @@ -7,6 +7,7 @@ * Prevent connections from entering Reactor after shutdown begins (#2377) * Better error handling during force shutdown (#2271) * Fix LoadError in CentOS 8 (#2381) + * Do not log EOFError when a client connection is closed without write (#2384) * Refactor * Change Events#ssl_error signature from (error, peeraddr, peercert) to (error, ssl_socket) (#2375) diff --git a/lib/puma/client.rb b/lib/puma/client.rb index 1b7c0ea018..f783bc42ee 100644 --- a/lib/puma/client.rb +++ b/lib/puma/client.rb @@ -155,7 +155,9 @@ def try_to_finish data = @io.read_nonblock(CHUNK_SIZE) rescue IO::WaitReadable return false - rescue SystemCallError, IOError, EOFError + rescue EOFError + # Swallow error, don't log + rescue SystemCallError, IOError raise ConnectionError, "Connection error detected during read" end diff --git a/lib/puma/server.rb b/lib/puma/server.rb index 804011e3ca..a6095c49e5 100644 --- a/lib/puma/server.rb +++ b/lib/puma/server.rb @@ -246,7 +246,11 @@ def run(background=true) client.close @events.parse_error e, client - rescue ConnectionError, EOFError, ThreadPool::ForceShutdown => e + rescue EOFError => e + client.close + + # Swallow, do not log + rescue ConnectionError, ThreadPool::ForceShutdown => e client.close @events.connection_error e, client