makara
makara copied to clipboard
add sidekiq middleware component to avoid reusing contexts between wo…
…rkers
Related to #151, I have confirmed that context reuse between tasks is taking place on recycled threads. This PR will avoid leaking contexts of previous tasks by clearing out the context as a post-task operation.
It would be great to get some eyes on this if it fixes the issue with Sidekiq workers!
I'll try to test it in our app where we're seeing ActiveRecord::ConnectionTimeoutError
exceptions once I can reliably reproduce them locally.
How do you manage to make Sidekiq work with read-replicas at all? Sidekiq jobs will usually fail because they start processing faster than the replica lag so the data the job has to work with will be missing or out of date unless Sidekiq connects directly to master. If you have a solution to that, I'd love to know!
We pointed background workers always to the primary (writer) for this reason and that they often were doing updates anyway.