Skip to content

Commit

Permalink
Add a connection timeout for remote region connections
Browse files Browse the repository at this point in the history
This will prevent a non-responsive remote region from hanging
the UI when trying to query for the replication backlog.

Regular ruby Timeout won't work here because the PG connection code
doesn't respond to the exception until after it has exhausted the
underlying libpq timeout logic.

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1796681
  • Loading branch information
carbonin committed Jan 31, 2020
1 parent 9ff0a84 commit 8098b63
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 @@ -261,12 +261,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 8098b63

Please sign in to comment.