9/28
Part 2 of 6 · Failures and retriesLearn and do
Find the bug: a retry that goes to the back
Here is levels 1 and 2 of the work queue, as many candidates first write it. Enqueue, reserve and the holder check all work. The dead-letter queue works too.
The bug is the one from the report: a failed task goes behind tasks that were enqueued after it (1 report). In the example, a, b and c are enqueued, w1 takes a, w2 takes b, and a fails. The next reserve should give a. This code gives c.
It's an easy bug to write, because it feels natural. The task is being enqueued again, so it gets the next number, like any new task. But a retry isn't a new task. Its place in line was decided when it first arrived.
In the editor, WorkQueue hands out c before the failed a. Run it, find the line in fail that gives a its new place, and fix it.