From e22dd5d8c9e17c29156c31ee6749b537df31dc7e Mon Sep 17 00:00:00 2001 From: Jake Frautschi Date: Fri, 6 May 2022 18:54:29 -0700 Subject: [PATCH] Don't require a DB connection, but release one if it is acquired --- sentry-rails/lib/sentry/rails/background_worker.rb | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/sentry-rails/lib/sentry/rails/background_worker.rb b/sentry-rails/lib/sentry/rails/background_worker.rb index 89e54e121..c3167c841 100644 --- a/sentry-rails/lib/sentry/rails/background_worker.rb +++ b/sentry-rails/lib/sentry/rails/background_worker.rb @@ -1,15 +1,10 @@ module Sentry class BackgroundWorker def _perform(&block) - # some applications have partial or even no AR connection - if ActiveRecord::Base.connected? - # make sure the background worker returns AR connection if it accidentally acquire one during serialization - ActiveRecord::Base.connection_pool.with_connection do - block.call - end - else - block.call - end + block.call + ensure + # make sure the background worker returns AR connection if it accidentally acquire one during serialization + ActiveRecord::Base.connection_pool.release_connection end end end