Skip to content

Commit

Permalink
Merge pull request ManageIQ#18010 from jrafanie/workaround_reconnect_…
Browse files Browse the repository at this point in the history
…failing_for_ssl_connections

Establish a new connection instead of reconnect!
  • Loading branch information
carbonin authored Sep 21, 2018
2 parents 3a2be6a + 2f236f6 commit 7467510
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
5 changes: 4 additions & 1 deletion app/models/miq_queue_worker_base/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,10 @@ def deliver_queue_message(msg)
if status == MiqQueue::STATUS_TIMEOUT
begin
_log.info("#{log_prefix} Reconnecting to DB after timeout error during queue deliver")
ActiveRecord::Base.connection.reconnect!

# Remove the connection and establish a new one since reconnect! doesn't always play nice with SSL postgresql connections
spec_name = ActiveRecord::Base.connection_specification_name
ActiveRecord::Base.establish_connection(ActiveRecord::Base.remove_connection(spec_name))
@worker.update_spid!
rescue => err
do_exit("Exiting worker due to timeout error that could not be recovered from...error: #{err.class.name}: #{err.message}", 1)
Expand Down
4 changes: 3 additions & 1 deletion app/models/miq_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,9 @@ def monitor

begin
_log.info("Reconnecting to database after error...")
ActiveRecord::Base.connection.reconnect!
# Remove the connection and establish a new one since reconnect! doesn't always play nice with SSL postgresql connections
spec_name = ActiveRecord::Base.connection_specification_name
ActiveRecord::Base.establish_connection(ActiveRecord::Base.remove_connection(spec_name))
rescue Exception => err
_log.error("#{err.message}, during reconnect!")
else
Expand Down
4 changes: 3 additions & 1 deletion app/models/miq_server/environment_management.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ def get_network_information
end

def validate_database
ActiveRecord::Base.connection.reconnect!
# Remove the connection and establish a new one since reconnect! doesn't always play nice with SSL postgresql connections
spec_name = ActiveRecord::Base.connection_specification_name
ActiveRecord::Base.establish_connection(ActiveRecord::Base.remove_connection(spec_name))

# Log the Versions
_log.info("Database Adapter: [#{ActiveRecord::Base.connection.adapter_name}], version: [#{ActiveRecord::Base.connection.database_version}]") if ActiveRecord::Base.connection.respond_to?(:database_version)
Expand Down
6 changes: 4 additions & 2 deletions app/models/miq_server/queue_management.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ def process_miq_queue
if status == "timeout"
begin
_log.info("Reconnecting to DB after timeout error during queue deliver")
ActiveRecord::Base.connection.reconnect!
# Remove the connection and establish a new one since reconnect! doesn't always play nice with SSL postgresql connections
spec_name = ActiveRecord::Base.connection_specification_name
ActiveRecord::Base.establish_connection(ActiveRecord::Base.remove_connection(spec_name))
rescue => err
_log.error("Error encountered during <ActiveRecord::Base.connection.reconnect!> error:#{err.class.name}: #{err.message}")
_log.error("Error encountered reconnecting to the database, error:#{err.class.name}: #{err.message}")
end
end

Expand Down

0 comments on commit 7467510

Please sign in to comment.