-
Notifications
You must be signed in to change notification settings - Fork 10
[fix] Thread callback ordering #53
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
PR Betterment#42 inadvertently flipped the order of `:thread` and `:perform`, and also pushed `:thread` far enough in that cleanup steps would happen after the `with_connection`'s `end` block in the connection plugin. This introduces the possibility of thread safety issues, or connections being held longer than intended (exhausting the connection pool / connection limits).
| pool = Concurrent::FixedThreadPool.new(jobs.length) | ||
| jobs.each do |job| | ||
| pool.post do | ||
| success.increment if run_job(job) |
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.
If you notice, run_job actually triggers the :perform callbacks before calling run, which triggers :thread.
This was never intended, and to reduce confusion, more callbacks have been fully inlined, and the methods have been reduced to a single perform(job) method.
argvniyx-enroute
left a comment
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.
domainlgtm
I'm adding regression coverage for the changes made in #53, and making one additional change in line with the way that the `:perform` callback [works in the `delayed_job` gem](https://github.com/collectiveidea/delayed_job/blob/ea4879dd3c2f3f5aa7f616a6f0fd58f2bbc2a481/lib/delayed/worker.rb#L313) - there is also now a test that will more explicitly check the order of callback events and behavior on job failure. Plus, while debugging in an app, I noticed that datadog tries to cast priority to a float, which was raising a method undefined error. So I added `Delayed::Priority#to_f` and added a test to cover all the explicit conversion methods (`to_s`, `to_i`, `to_f`, `to_d`).
/no-platform
/domain @argvniyx-enroute @mavenraven
PR #42 inadvertently flipped the order of
:threadand:perform, and also pushed:threadfar enough in that cleanup steps would happen after thewith_connection'sendblock in the connection plugin.This introduces the possibility of thread safety issues, or connections being held longer than intended (exhausting the connection pool / connection limits).