-
-
Notifications
You must be signed in to change notification settings - Fork 513
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
Conversation
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.
@@ -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 |
There was a problem hiding this comment.
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 😕
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
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.