Skip to content

Replace manual connection control with abstracted execution wrapper #1746

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

Closed
wants to merge 2 commits into from

Conversation

st0012
Copy link
Collaborator

@st0012 st0012 commented Feb 25, 2022

As described in this document, Rails.application.executor.wrap should provide a higher-level of abstraction to achieve concurrent execution, which includes returning acquired ActiveRecord connection.

This prevents us from locking in a particular ORM's database connection mechanism.

As described in https://github.com/rails/rails/blob/1d9d53831600c974fcccd4b5574f0e03d7e1513c/guides/source/threading_and_code_execution.md#executor

`Rails.application.executor.wrap` should provide a higher-level of
abstraction to achieve concurrent execution, which includes returning
acquired ActiveRecord connection.

This prevents us from locking in a particular ORM's database connection
mechanism.
@st0012 st0012 added this to the 5.2.0 milestone Feb 25, 2022
@st0012 st0012 self-assigned this Feb 25, 2022
@@ -2,7 +2,7 @@ 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
::Rails.application.executor.wrap do
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After Rails 7.0, it'll capture the block's exception and report it, which will enter here again and cause infinite loop. So now I think this may be a bad idea 😕

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but our @__sentry_captured fix will avoid the loop right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not, because the loop will be caused by the exception from SDK (if there's any), instead of the one we capture.
For example, if an event for ZeroDivisionError caused a NoMethodError during serialization, that NoMethodError will be captured and became a new event. If that NoMethodError is somehow a problem of the SDK code and/or problematic contextual data, it'll be an infinite loop.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right but then we can just add another rescue here, SDK should fail gracefully internally.
Or move this rescue over to both _perform methods.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah but that feels ugly. And if this doesn't actually solve #1745, I don't see the necessity to implement it like this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah ok just read the follow up in the other issue

@st0012 st0012 modified the milestones: 5.2.0, 5.3.0 Mar 12, 2022
@st0012 st0012 removed this from the 5.3.0 milestone Mar 20, 2022
@st0012 st0012 closed this Mar 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants