diff --git a/app/models/miq_region_remote.rb b/app/models/miq_region_remote.rb index b441e610332..c5b6917ad8f 100644 --- a/app/models/miq_region_remote.rb +++ b/app/models/miq_region_remote.rb @@ -78,7 +78,7 @@ def self.connection_parameters_for(config) return host, port, username, password, database, adapter end - def self.with_remote_connection(host, port, username, password, database, adapter) + def self.with_remote_connection(host, port, username, password, database, adapter, connect_timeout = 0) # Don't allow accidental connections to localhost. A blank host will # connect to localhost, so don't allow that at all. host = host.to_s.strip @@ -92,12 +92,13 @@ def self.with_remote_connection(host, port, username, password, database, adapte begin pool = establish_connection({ - :adapter => adapter, - :host => host, - :port => port, - :username => username, - :password => password, - :database => database + :adapter => adapter, + :host => host, + :port => port, + :username => username, + :password => password, + :database => database, + :connect_timeout => connect_timeout }.delete_blanks) conn = pool.connection yield conn diff --git a/app/models/pglogical_subscription.rb b/app/models/pglogical_subscription.rb index 1cb6f5e4f4a..12f16c65266 100644 --- a/app/models/pglogical_subscription.rb +++ b/app/models/pglogical_subscription.rb @@ -258,12 +258,12 @@ def decrypted_password end def remote_region_lsn - with_remote_connection(&:xlog_location) + with_remote_connection(5.seconds) { |conn| conn.xlog_location } end - def with_remote_connection + def with_remote_connection(connect_timeout = 0) find_password - MiqRegionRemote.with_remote_connection(host, port || 5432, user, decrypted_password, dbname, "postgresql") do |conn| + MiqRegionRemote.with_remote_connection(host, port || 5432, user, decrypted_password, dbname, "postgresql", connect_timeout) do |conn| yield conn end end