(maint) Use timeout builtin to TCPSocket when opening sockets.

This commit is contained in:
isaac-hammes 2023-03-02 11:27:55 -08:00
parent 87274a2d51
commit 713a4a2c9d

View file

@ -632,15 +632,13 @@ module Vmpooler
# This should supercede the open_socket method in the Pool Manager # This should supercede the open_socket method in the Pool Manager
def open_socket(host, domain = nil, timeout = 5, port = 22, &_block) def open_socket(host, domain = nil, timeout = 5, port = 22, &_block)
Timeout.timeout(timeout) do target_host = host
target_host = host target_host = "#{host}.#{domain}" if domain
target_host = "#{host}.#{domain}" if domain sock = TCPSocket.new(target_host, port, connect_timeout: timeout)
sock = TCPSocket.new target_host, port begin
begin yield sock if block_given?
yield sock if block_given? ensure
ensure sock.close
sock.close
end
end end
end end