From 0a0e566286c9b06b11bc3ad974fe23c08267bab0 Mon Sep 17 00:00:00 2001 From: Adam Ruzicka Date: Tue, 4 Aug 2020 14:00:25 +0200 Subject: [PATCH] DB pool timeout error reproducer --- lib/dynflow/executors.rb | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/lib/dynflow/executors.rb b/lib/dynflow/executors.rb index 00523f72..14839e43 100644 --- a/lib/dynflow/executors.rb +++ b/lib/dynflow/executors.rb @@ -5,19 +5,13 @@ module Executors require 'dynflow/executors/parallel' class << self - # Every time we run a code that can be defined outside of Dynflow, - # we should wrap it with this method, and we can ensure here to do - # necessary cleanup, such as cleaning ActiveRecord connections def run_user_code - # Here we cover a case where the connection was already checked out from - # the pool and had opened transactions. In that case, we should leave the - # cleanup to the other runtime unit which opened the transaction. If the - # connection was checked out or there are no opened transactions, we can - # safely perform the cleanup. - no_previously_opened_transactions = active_record_open_transactions.zero? - yield + # Always acquire a connection from the DB pool, even if it may not be + # needed + ::ActiveRecord::Base.connection_pool.with_connection do |_conn| + yield + end ensure - ::ActiveRecord::Base.clear_active_connections! if no_previously_opened_transactions && active_record_connected? ::Logging.mdc.clear if defined? ::Logging end