diff --git a/activerecord/lib/active_record/query_cache.rb b/activerecord/lib/active_record/query_cache.rb
index <HASH>..<HASH> 100644
--- a/activerecord/lib/active_record/query_cache.rb
+++ b/activerecord/lib/active_record/query_cache.rb
@@ -28,8 +28,8 @@ module ActiveRecord
     end
 
     def self.complete(_)
-      unless ActiveRecord::Base.connected? && ActiveRecord::Base.connection.transaction_open?
-        ActiveRecord::Base.clear_active_connections!
+      ActiveRecord::Base.connection_handler.connection_pool_list.each do |pool|
+        pool.release_connection if pool.active_connection? && !pool.connection.transaction_open?
       end
     end
Try harder to avoid making a connection while releasing it

connected? doesn't mean what we need here.