Skip to content

Commit

Permalink
Merge pull request #1334 from respire/fix_minissl_socket_blocking_close
Browse files Browse the repository at this point in the history
fix #1214 Puma >= 3.6.1 + SSL + Persistent Connections. Puma Hangs :(
  • Loading branch information
evanphx committed Jun 13, 2017
2 parents 0886aef + 4238235 commit 63f3c51
Showing 1 changed file with 18 additions and 25 deletions.
43 changes: 18 additions & 25 deletions lib/puma/minissl.rb
Expand Up @@ -96,33 +96,26 @@ def flush
@socket.flush
end

def close
begin
# Try to setup (so that we can then close them) any
# partially initialized sockets.
while @engine.init?
# 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)
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

@engine.inject notify
done = @engine.shutdown
def should_drop_bytes?
@engine.init? || !@engine.shutdown
end

break if done
def close
begin
# 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.
while should_drop_bytes?
return if read_and_drop(1) == :timeout
end
rescue IOError, SystemCallError
# nothing
Expand Down

0 comments on commit 63f3c51

Please sign in to comment.