1
0
Fork 0
mirror of https://github.com/puma/puma.git synced 2022-11-09 13:48:40 -05:00

Merge pull request #1334 from respire/fix_minissl_socket_blocking_close

fix #1214 Puma >= 3.6.1 + SSL + Persistent Connections. Puma Hangs :(
This commit is contained in:
Evan Phoenix 2017-06-13 10:29:00 -07:00 committed by GitHub
commit 63f3c51e98

View file

@ -96,33 +96,26 @@ module Puma
@socket.flush
end
def read_and_drop(timeout = 1)
return :timeout unless IO.select([@socket], nil, nil, timeout)
read_nonblock(1024)
:drop
rescue Errno::EAGAIN
# do nothing
:eagain
end
def should_drop_bytes?
@engine.init? || !@engine.shutdown
end
def close
begin
# Try to setup (so that we can then close them) any
# partially initialized sockets.
while @engine.init?
# Read any drop any partially initialized sockets and any received bytes during shutdown.
# Don't let this socket hold this loop forever.
# If it can't send more packets within 1s, then
# give up.
return unless IO.select([@socket], nil, nil, 1)
begin
read_nonblock(1024)
rescue Errno::EAGAIN
end
end
done = @engine.shutdown
while true
enc = @engine.extract
@socket.write enc
notify = @socket.sysread(1024)
@engine.inject notify
done = @engine.shutdown
break if done
# If it can't send more packets within 1s, then give up.
while should_drop_bytes?
return if read_and_drop(1) == :timeout
end
rescue IOError, SystemCallError
# nothing