diff --git a/lib/puma/minissl.rb b/lib/puma/minissl.rb index 88ded261d5..7332926ac3 100644 --- a/lib/puma/minissl.rb +++ b/lib/puma/minissl.rb @@ -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