Description
Symfony version(s) affected
5.4 and higher
Description
DelayStamp allows negative delays values which result in an error when using RabbitMQ.
The delay stamp creates a delay queue and sets the x-expires and x-message-ttl to a negative value which is not allowed by RabbitMQ and results in an error:
Server channel error: 406, message: PRECONDITION_FAILED - invalid arg 'x-expires' for queue 'xxxxxxxxxxx-32000_delay' in vhost '/': {value_negative,-22000}
How to reproduce
Create a message with a delay stamp using DelayStamp::delayUntil(\DateTimeInterface $dateTime) with a DateTime in the past.
or
Create a message with a delay stamp using DelayStamp::__construct(int $delay) with a negative delay.
Possible Solution
Ensure the DelayStamp::getDelay() function always returns a positive value, unless other Transports do allow negative delays. In that case, the AMQP transport Connection::createDelayQueue() must turn any negative delays to 0.
Perhaps even better is to ensure the delay queue is not setup at all for negative delays by checking of 0< instead of 0!== in
Connection::publish()
Additional Context
The value of the TTL argument or policy must be a non-negative integer (equal to or greater than zero), describing the TTL period in milliseconds.
The value of the expiration field describes the TTL period in milliseconds. The same constraints as for x-message-ttl apply.