There seems to be a logic bug that causes handleDeadLetter to never fire. Here's our setup:
We have a queue worker with 3 max tries. Whenever an item fails, it throws a DelayedRequeueException, so we do not trigger releaseItem so as to ensure the tries counter does not go down to zero again.
That means we have the following flow:
- Queue item enters queue with tries = 0
- Queue item is claimed, tries = 1
- Queue item fails, tries = 1 and expiry > 0
- Expiry is reset to 0 by system cron hook
- Queue item is claimed, tries = 2
- Queue item fails, tries = 2 and expiry > 0
- Expiry is reset to 0 by system cron hook
- Queue item is claimed, tries = 3
- Queue item fails, tries = 3 and expiry > 0
- Expiry is reset to 0 by system cron hook
- Queue item is claimed
At this point, we're in DeadLetterDatabaseQueue::claimItem.
A bit further down, we build a query that checks for this (see bold):
SELECT data, created, item_id, tries FROM {' . static::TABLE_NAME . '} q WHERE expire = 0 AND name = :name AND tries < :max_tries ORDER BY created, item_id ASC
Queue items that failed 3 times will not be considered as valid items in this query. That part seems fine.
However, that means the item's tries counter will never be increased again, which is what the check to call handleDeadLetter() needs:
if ($isDeadLetter && $item->tries > $maxTries) {
$item->tries can never be bigger than $maxTries, only equal to it, so the code inside that if clause is never hit.
Suggestions
I think the simplest way to solve this is to have a separate cron hook that queries the database like this:
SELECT data, created, item_id, tries FROM queue_unique WHERE expire = 0 AND name = :name AND tries = :max_tries ORDER BY created, item_id ASC
This is our list of dead letter items, so we process them with the same logic that is currently in DeadLetterDatabaseQueue::claimItem.
Issue fork dead_letter_queue-3532140
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #4
dieterholvoet commentedThanks for reporting!