From c063af38bfe040d57c362e3dc3dee25c26c80b66 Mon Sep 17 00:00:00 2001 From: MSP-Greg Date: Mon, 30 Mar 2020 18:22:10 -0500 Subject: [PATCH] control_cli.rb - improve ssl connection shutdown (#2211) Most sockets are closed in gc, but we should try to close all of them in code. Change closes the TCP connection, previously it wasn't. --- History.md | 1 + lib/puma/control_cli.rb | 13 ++++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/History.md b/History.md index 12fd6b5e94..d521b86e0a 100644 --- a/History.md +++ b/History.md @@ -1,6 +1,7 @@ ## Master * Features + * Improve SSL connection closing in Puma::ControlCLI (#2211) * Add pumactl `thread-backtraces` command to print thread backtraces (#2053) * Configuration: `environment` is read from `RAILS_ENV`, if `RACK_ENV` can't be found (#2022) * Do not set user_config to quiet by default to allow for file config (#2074) diff --git a/lib/puma/control_cli.rb b/lib/puma/control_cli.rb index 3343b618e4..063b74e188 100644 --- a/lib/puma/control_cli.rb +++ b/lib/puma/control_cli.rb @@ -146,8 +146,9 @@ def send_request require 'openssl' OpenSSL::SSL::SSLSocket.new( TCPSocket.new(uri.host, uri.port), - OpenSSL::SSL::SSLContext.new - ).tap(&:connect) + OpenSSL::SSL::SSLContext.new) + .tap { |ssl| ssl.sync_close = true } # default is false + .tap(&:connect) when "tcp" TCPSocket.new uri.host, uri.port when "unix" @@ -191,7 +192,13 @@ def send_request message response.last if PRINTABLE_COMMANDS.include?(@command) end ensure - server.close if server && !server.closed? + if server + if uri.scheme == "ssl" + server.sysclose + else + server.close unless server.closed? + end + end end def send_signal