Skip to content

Commit

Permalink
More elaborate exception handling. Fixes puma#2699.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Sep 16, 2021
1 parent 319f84d commit ccd0843
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/puma/server.rb
Expand Up @@ -356,7 +356,10 @@ def handle_servers
pool << client
end
end
rescue Object => e
rescue IOError, Errno::EBADF
# In the case that any of the sockets are unexpectedly close.
raise
rescue StandardError => e
@events.unknown_error e, nil, "Listen loop"
end
end
Expand Down
9 changes: 9 additions & 0 deletions test/config/broken_io.rb
@@ -0,0 +1,9 @@
require 'objspace'

app do |env|
ios = ObjectSpace.each_object(IO).to_a.select {|io| io.is_a?(TCPServer)}

ios.each(&:close)

[200, [], [ios.inspect]]
end
28 changes: 28 additions & 0 deletions test/test_broken_io.rb
@@ -0,0 +1,28 @@
require_relative "helper"
require_relative "helpers/integration"

class TestBrokenIO < TestIntegration
def wait_for(pattern)
while line = @server.gets
if line =~ pattern
return true
end
end
end

def test_broken_io
@tcp_port = UniquePort.call

cli_server "-b tcp://#{HOST}:#{@tcp_port} -C test/config/broken_io.rb test/rackup/hello.ru"

# Invoke a request which must be rejected
stdout_str, status = Open3.capture2("curl #{HOST}:#{@tcp_port}")

Process.kill :INT , @pid

wait_for(/Goodbye/)

@server.close
@server = nil
end
end

0 comments on commit ccd0843

Please sign in to comment.