-
-
Notifications
You must be signed in to change notification settings - Fork 505
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
Prevent background workers from holding ActiveRecord connections #1320
Conversation
47493ba
to
238f76f
Compare
it appears as though this strategy requires that the background worker get a connection to enter the block. in our app with 1 db connection per unicorn the background worker is erroring out:
if the breadcrumbs do indeed need to query the DB then we should either bump up our connection limit to 2 or force synchronous behavior. but it seems like the option to have async without a db connection is not possible. |
I think your question is legit and with the current background worker design, it will need 2 connections per unicorn worker to work smoothly. But to have a more detailed discussion, can you also share your application's setup (server, worker) and resource limitation (e.g. you're using heroku and your DB plan only allows 20 connections)? |
Actually, it'd be great if you can open an issue report and we can discuss there. It'll be easier for other people to chime in too. |
done: #1808. if you have edits for generalizing the title please let me know. |
When the SDK's background workers serializing events for a Rails application, it could implicitly trigger database queries by serializing data that contain ActiveRecord models/records (e.g. when serializing breadcrumbs). And by triggering the queries, those workers will also obtain database connections from the connection pool and hold them forever. This will later cause the application to run out of available connections.
This PR solves the issue by using
ActiveRecord::ConnectionPool#with_connection
method to force background workers to release any connection they might obtain during the serialization work.