Add vsphere_connection_timeout to prevent thread hangs when vSphere unresponsive

This commit is contained in:
Mahima Singh 2026-03-13 11:49:16 +05:30
parent 4a57a270f6
commit d9aee6baee

View file

@ -3,6 +3,7 @@
require 'bigdecimal' require 'bigdecimal'
require 'bigdecimal/util' require 'bigdecimal/util'
require 'rbvmomi' require 'rbvmomi'
require 'timeout'
require 'vmpooler/providers/base' require 'vmpooler/providers/base'
module Vmpooler module Vmpooler
@ -657,7 +658,9 @@ module Vmpooler
end end
def vsphere_connection_ok?(connection) def vsphere_connection_ok?(connection)
_result = connection.serviceInstance.CurrentTime Timeout.timeout(vsphere_connection_timeout) do
_result = connection.serviceInstance.CurrentTime
end
true true
rescue StandardError rescue StandardError
false false
@ -671,7 +674,8 @@ module Vmpooler
connection = RbVmomi::VIM.connect host: provider_config['server'], connection = RbVmomi::VIM.connect host: provider_config['server'],
user: provider_config['username'], user: provider_config['username'],
password: provider_config['password'], password: provider_config['password'],
insecure: provider_config['insecure'] || false insecure: provider_config['insecure'] || false,
timeout: vsphere_connection_timeout
metrics.increment('connect.open') metrics.increment('connect.open')
connection connection
rescue StandardError => e rescue StandardError => e
@ -684,6 +688,12 @@ module Vmpooler
end end
end end
def vsphere_connection_timeout
timeout = provider_config['vsphere_timeout'] ||
global_config&.dig(:config, 'vsphere_timeout') || 60
timeout.to_i
end
# 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)
target_host = host target_host = host