Skip to content

Commit

Permalink
[close #2371] Do not log EOFError
Browse files Browse the repository at this point in the history
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
  • Loading branch information
schneems committed Sep 25, 2020
1 parent 8c5ef9b commit dfd198d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions History.md
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion lib/puma/client.rb
Expand Up @@ -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

Expand Down
6 changes: 5 additions & 1 deletion lib/puma/server.rb
Expand Up @@ -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
Expand Down

0 comments on commit dfd198d

Please sign in to comment.