(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
def open_socket(host, domain = nil, timeout = 5, port = 22, &_block)
Timeout.timeout(timeout) do
target_host = host
target_host = "#{host}.#{domain}" if domain
sock = TCPSocket.new target_host, port
begin
yield sock if block_given?
ensure
sock.close
end
target_host = host
target_host = "#{host}.#{domain}" if domain
sock = TCPSocket.new(target_host, port, connect_timeout: timeout)
begin
yield sock if block_given?
ensure
sock.close
end
end