Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

exception happened in background worker: ActiveRecord::ConnectionNotEstablished #1745

Closed
sdogruyol opened this issue Feb 24, 2022 · 7 comments · Fixed by #1769
Closed

exception happened in background worker: ActiveRecord::ConnectionNotEstablished #1745

sdogruyol opened this issue Feb 24, 2022 · 7 comments · Fixed by #1769
Assignees
Projects
Milestone

Comments

@sdogruyol
Copy link

sdogruyol commented Feb 24, 2022

Issue Description

This started to happen after we upgraded our application from Rails 6.1 to Rails 7.0.2.2.

Sentry SDK just crashes in the middle of the request with an unrelated stacktrace and the following error

ERROR -- sentry: exception happened in background worker: ActiveRecord::ConnectionNotEstablished

The weird part is that our application uses Sequel and not ActiveRecord.

Reproduction Steps

Not available

Expected Behavior

Should not crash the request

Actual Behavior

Crashes the request with 500 error

Ruby Version

3.0.3

SDK Version

5.0.2

Integration and Its Version

5.0.2

Sentry Config

# frozen_string_literal: true

Sentry.init do |config|
  config.dsn = ENV.fetch('SENTRY_RAVEN_KEY')
  config.send_default_pii = true
end
@st0012
Copy link
Collaborator

st0012 commented Feb 25, 2022

@sdogruyol Thanks for reporting the issue.

The root cause is that we have this code in the SDK's background worker to make sure we release ActiveRecord's connection if it acquired one. The code was written assuming the client would use ActiveRecord, which is not the case for you (and perhaps some other users).

So in #1746, I tried to replace the code with a higher-level helper. But because I don't know how you set up Sequal with your Rails app, I can't test it for you. Can you try the branch and let me know if it fixes the issue?

@st0012 st0012 added this to To do in 5.x via automation Feb 25, 2022
@st0012 st0012 added this to the 5.2.0 milestone Feb 25, 2022
@sdogruyol
Copy link
Author

Hey @st0012 thanks a lot for the response.

I just tried your branch and it doesn't seem to fix the problem. Still getting the same exception happened in background worker: ActiveRecord::ConnectionNotEstablished exception.

@st0012
Copy link
Collaborator

st0012 commented Mar 1, 2022

@sdogruyol can you set config.debug = true in your initializer and provide me the error output? (which should include backtrace)

@ajparise
Copy link

The weird part is that our application uses Sequel and not ActiveRecord.

I am experiencing this issue after upgrading sentry-rails from 4.2.2 to 5.1.0.
The app is running Rails 5.2.6.2, it uses Mongoid and AR, but it does not have a persistent or default AR connection setup.

As a workaround I've resorted to synchronous event sending.

config.background_worker_threads = 0

@st0012
Copy link
Collaborator

st0012 commented Mar 20, 2022

@sdogruyol @ajparise sorry for the delay. I've added #1769 to address the issue, which I think should solve the problem. it'd be great if you can help me verify the fix, thx 🙂

@ajparise
Copy link

@st0012 verified, thanks for the fix.

@st0012
Copy link
Collaborator

st0012 commented Mar 22, 2022

@ajparise thank you 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
5.x
Done
Development

Successfully merging a pull request may close this issue.

3 participants