Skip to content

Conversation

@smudge
Copy link
Member

@smudge smudge commented Apr 2, 2025

/no-platform
/domain @argvniyx-enroute @mavenraven

PR #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).

smudge added 4 commits April 2, 2025 17:59
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)
Copy link
Member Author

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.

Copy link

@argvniyx-enroute argvniyx-enroute left a comment

Choose a reason for hiding this comment

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

domainlgtm

@smudge smudge merged commit 2ea5f07 into Betterment:main Apr 2, 2025
27 checks passed
@smudge smudge deleted the thread-callback-fix branch April 2, 2025 22:20
smudge added a commit to smudge/delayed that referenced this pull request Apr 3, 2025
smudge added a commit to smudge/delayed that referenced this pull request Apr 3, 2025
smudge added a commit that referenced this pull request Apr 3, 2025
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`).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants