From 1e516f5fb7330633f1f0d751e47fa62221cc7f0a Mon Sep 17 00:00:00 2001 From: st0012 Date: Sun, 20 Mar 2022 14:53:30 +0000 Subject: [PATCH 1/2] Check if ActiveRecord connection exists before calling AR connection pool --- sentry-rails/lib/sentry/rails/background_worker.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/sentry-rails/lib/sentry/rails/background_worker.rb b/sentry-rails/lib/sentry/rails/background_worker.rb index 771ded58e..89e54e121 100644 --- a/sentry-rails/lib/sentry/rails/background_worker.rb +++ b/sentry-rails/lib/sentry/rails/background_worker.rb @@ -1,8 +1,13 @@ module Sentry class BackgroundWorker def _perform(&block) - # make sure the background worker returns AR connection if it accidentally acquire one during serialization - ActiveRecord::Base.connection_pool.with_connection do + # 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 end From f10a4ff5947a69638467fe2505ebb19222241910 Mon Sep 17 00:00:00 2001 From: st0012 Date: Tue, 22 Mar 2022 12:33:35 +0000 Subject: [PATCH 2/2] Update changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b283bdbb1..b75260735 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ - Add `config.rails.register_error_subscriber` to control error reporter integration [#1771](https://github.com/getsentry/sentry-ruby/pull/1771) - Fixes [#1731](https://github.com/getsentry/sentry-ruby/issues/1731), [#1754](https://github.com/getsentry/sentry-ruby/issues/1754), and [#1765](https://github.com/getsentry/sentry-ruby/issues/1765) - [Discussion thread and explanation on the decision](https://github.com/rails/rails/pull/43625#issuecomment-1072514175) +- Check if ActiveRecord connection exists before calling AR connection pool [#1769](https://github.com/getsentry/sentry-ruby/pull/1769) + - Fixes [#1745](https://github.com/getsentry/sentry-ruby/issues/1745) ## 5.2.1