From 42382357604a11631a17add24b3cd2e42559a11a Mon Sep 17 00:00:00 2001 From: Respire Date: Tue, 13 Jun 2017 14:09:34 +0800 Subject: [PATCH] fix #1214 Puma >= 3.6.1 + SSL + Persistent Connections. Puma Hangs :( --- lib/puma/minissl.rb | 43 ++++++++++++++++++------------------------- 1 file changed, 18 insertions(+), 25 deletions(-) diff --git a/lib/puma/minissl.rb b/lib/puma/minissl.rb index afde2d94..9730ae74 100644 --- a/lib/puma/minissl.rb +++ b/lib/puma/minissl.rb @@ -81,33 +81,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? - # 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 + # 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