Commit d080906
committed
Prevent ThreadedWorker from leaking enqueue lifecycle callbacks
Delayed::Plugin callbacks register against Delayed::Worker.lifecycle
(the base class), and Delayed::Job.enqueue runs that same base
lifecycle. Delayed::Worker#initialize calls self.class.setup_lifecycle,
which rebuilds the lifecycle on the class it is called on. Since
ThreadedWorker is a subclass, setup_lifecycle reset a different
lifecycle than the base one the plugins append to. The base lifecycle
was therefore never reset, and every ThreadedWorker.new added another
before(:enqueue) callback to it.
The before(:enqueue) callback creates a PollableJobModel row, so the
accumulation caused a single enqueue to create many pollable rows.
Production is unaffected since a worker is created once per process.
Delegate setup_lifecycle and lifecycle on ThreadedWorker to the base
class so each instantiation rebuilds the same lifecycle cleanly.1 parent 12e5d15 commit d080906
2 files changed
Lines changed: 23 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
3 | 16 | | |
4 | 17 | | |
5 | 18 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
25 | 35 | | |
26 | 36 | | |
27 | 37 | | |
| |||
0 commit comments