-
-
Couldn't load subscription status.
- Fork 290
Description
I noticed that moveExpired method can cause problems when multiple workers are running simultaneously. If multiple workers call zrevrangebyscore at the same time, before zremrangebyscore is called, both will get the same message IDs and will add them to the waiting queue, causing duplicate entries.
If this happens, one of two problems will occur:
a) Duplicate message ID will be fetched after the job is already processed, causing queue to crash with this exception:
PHP Notice 'yii\base\ErrorException' with message 'Undefined offset: 1' in vendor/yiisoft/yii2-queue/src/drivers/redis/Queue.php:106
This happens because the payload was already deleted and the script doesn't check if it actually got the payload before trying to parse it.
b) Two or more worker processes will get the same duplicated message ID, causing the same job to be executed multiple times in parallel.
Steps to repeat:
- Launch multiple workers (4+ recommended) that listen to the queue with short wait time
- Add a couple thousand jobs to the queue with a delay(30s)
- Wait for errors