From d9aee6baeef39e64fc8f699f623a21f0cade4104 Mon Sep 17 00:00:00 2001 From: Mahima Singh <105724608+smahima27@users.noreply.github.com> Date: Fri, 13 Mar 2026 11:49:16 +0530 Subject: [PATCH] Add vsphere_connection_timeout to prevent thread hangs when vSphere unresponsive --- lib/vmpooler/providers/vsphere.rb | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/vmpooler/providers/vsphere.rb b/lib/vmpooler/providers/vsphere.rb index 921ab1a..d412dfe 100644 --- a/lib/vmpooler/providers/vsphere.rb +++ b/lib/vmpooler/providers/vsphere.rb @@ -3,6 +3,7 @@ require 'bigdecimal' require 'bigdecimal/util' require 'rbvmomi' +require 'timeout' require 'vmpooler/providers/base' module Vmpooler @@ -657,7 +658,9 @@ module Vmpooler end def vsphere_connection_ok?(connection) - _result = connection.serviceInstance.CurrentTime + Timeout.timeout(vsphere_connection_timeout) do + _result = connection.serviceInstance.CurrentTime + end true rescue StandardError false @@ -671,7 +674,8 @@ module Vmpooler connection = RbVmomi::VIM.connect host: provider_config['server'], user: provider_config['username'], password: provider_config['password'], - insecure: provider_config['insecure'] || false + insecure: provider_config['insecure'] || false, + timeout: vsphere_connection_timeout metrics.increment('connect.open') connection rescue StandardError => e @@ -684,6 +688,12 @@ module Vmpooler 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 def open_socket(host, domain = nil, timeout = 5, port = 22, &_block) target_host = host