From f69f0211dfd06692f484d3c230ee492dde7f7afd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Guitaut?= Date: Thu, 28 Nov 2024 11:27:58 +0100 Subject: [PATCH] DEV: Fix flaky spec related to Scheduler::Defer MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In some cases in CI env, it seems the AR connection isn’t available and the `ensure` block is executed. It’s calling `#verify!` on the connection, so it can fail sometimes. This is probably why `#clear_active_connections!` was failing too sometimes. Here, we just check the connection is present before clearing the connections. --- lib/scheduler/defer.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/scheduler/defer.rb b/lib/scheduler/defer.rb index d6a3132cd4f..fdf76c5c2cf 100644 --- a/lib/scheduler/defer.rb +++ b/lib/scheduler/defer.rb @@ -136,8 +136,9 @@ module Scheduler rescue => ex Discourse.handle_job_exception(ex, message: "Processing deferred code queue") ensure - ActiveRecord::Base.connection.verify! - ActiveRecord::Base.connection_handler.clear_active_connections! + if ActiveRecord::Base.connection + ActiveRecord::Base.connection_handler.clear_active_connections! + end if start @stats_mutex.synchronize do stats = @stats[desc]