tarantool / queue

Create task queues, add and take jobs, monitor failed tasks
Other
234 stars 52 forks source link

driver: possible data races in `kick` method #231

Open DerekBum opened 2 months ago

DerekBum commented 2 months ago

kick method is used to unbury several tasks in the tube. After analyzing this method for drivers fifo, fifottl, utube, utubettl, I came to the conclusion, that it still possible to get a data race and incorrect, unexpected result.

https://github.com/tarantool/queue/blob/aa7c092a1f2ac80d3cfc63c75595d10c5a95c908/queue/abstract/driver/fifo.lua#L158-L173

We take a task with minimal task_id and BURIED status. After that we are updating it, commiting. But lua can also yield before WAL write. So this very task could also be taken in a parallel kick call for the second time.

Possible fix: do changes inside a transaction, like in put, take methods. But there is a subtle point here (which is described in a comment below). https://github.com/tarantool/queue/blob/aa7c092a1f2ac80d3cfc63c75595d10c5a95c908/queue/abstract/driver/fifo.lua#L101-L117

### Tasks
- [ ] `fifo`
- [ ] `fifottl`
- [ ] `utube`
- [ ] `utubettl`