diff --git a/sentry-rails/lib/sentry/rails/background_worker.rb b/sentry-rails/lib/sentry/rails/background_worker.rb index 2c0cc7a71..36c362e36 100644 --- a/sentry-rails/lib/sentry/rails/background_worker.rb +++ b/sentry-rails/lib/sentry/rails/background_worker.rb @@ -2,14 +2,18 @@ module Sentry class BackgroundWorker - def _perform(&block) - block.call - ensure - # 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.release_connection + module ActiveRecordConnectionPatch + def _perform(&block) + super(&block) + ensure + # 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.release_connection + end end end end end + +Sentry::BackgroundWorker.prepend(Sentry::BackgroundWorker::ActiveRecordConnectionPatch)