Skip to content

Commit

Permalink
control_cli.rb - improve ssl connection shutdown (#2211)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
MSP-Greg committed Mar 30, 2020
1 parent c9b2fa2 commit c063af3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions 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)
Expand Down
13 changes: 10 additions & 3 deletions lib/puma/control_cli.rb
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c063af3

Please sign in to comment.