You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Possible unthrottled spinloop when jobs fail to deserailize #41
Working with @emmaoberstein on setting up a new queue, we discovered that there is a condition when the worker will get stuck in a spinloop, running the pickup query multiple times per second (effectively disobeying the sleep_delay config).
The likeliest reproduction would be to enqueue a job that fails deserialization completely, or that otherwise prevents the usual job cleanup (e.g. it crashes the thread).
Here's where the work_off method hits the spinloop:
defwork_off(num=100)success=Concurrent::AtomicFixnum.new(0)failure=Concurrent::AtomicFixnum.new(0)num.timesdojobs=reserve_jobsbreakifjobs.empty?# jobs is not emptypool=Concurrent::FixedThreadPool.new(jobs.length)jobs.eachdo |job|
pool.postdo# Exception encountered when `payload_object` is first called, e.g. job fails to deserialize# - success and failure are never incremented# - job remains in queue and is immediately returned by the next `reserve_jobs` without waitingendendpool.shutdownpool.wait_for_terminationbreakifstop?end[success,failure].map(&:value)end
There a few ways I could think to fix this:
Add a new "inner loop" delay that sets a minimum amount of time in between each iteration of num.times do.
Bail from the loop if neither success nor failure were incremented (i.e. no work got done).
Ensure that job cleanup happens in all cases (except for complete loss of DB connection), to ensure that reserve_jobs won't immediately return the same job again (due to exponential backoff).
All of these feel fairly reasonable, though I'd be inclined to explore the second and third. (Adding a new delay would require more tuning & testing and would not actually address the underlying failure mode for the job.) So, actually, I'd want to start with the third option, since it would likely also address the remaining issue in #23.
Activity
Fix spin-loop/cleanup failure mode within run loop
Fix spin-loop/cleanup failure mode within run loop (#42)
smudge commentedon Jun 27, 2024
Should be resolved by #42
Add a config for enforcing a minimum job reserve interval (default: 0…