Skip to content

Commit

Permalink
Merge pull request #19791 from carbonin/add_timeout_to_remote_region_…
Browse files Browse the repository at this point in the history
…connection

Add a connection timeout for remote region connections

(cherry picked from commit 3394f48)

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1798526
  • Loading branch information
jrafanie authored and simaishi committed Feb 21, 2020
1 parent e31fad5 commit b496935
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
15 changes: 8 additions & 7 deletions app/models/miq_region_remote.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions app/models/pglogical_subscription.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b496935

Please sign in to comment.