Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RabbitMQ PRECONDITION_FAILED - unknown delivery tag

Tags:

php

rabbitmq

amqp

We have a PHP app that forwards messages from RabbitMQ to connected devices down a WebSocket connection (PHP AMQP pecl extension v1.7.1 & RabbitMQ 3.6.6).

Messages are consumed from an array of queues (1 per websocket connection), and are acknowledged by the consumer when we receive confirmation over the websocket that the message has been received (so we can requeue messages that are not delivered in an acceptable timeframe). This is done in a non-blocking fashion.

99% of the time, this works perfectly, but very occasionally we receive an error "RabbitMQ PRECONDITION_FAILED - unknown delivery tag ". This closes the channel. In my understanding, this exception is a result of one of the following conditions:

  1. The message has already been acked or rejected.
  2. An ack is attempted over a channel the message was not delivered on.
  3. An ack is attempted after the message timeout (ttl) has expired.

We have implemented protections for each of the above cases but yet the problem continues.

I realise there are number of implementation details that could impact this, but at a conceptual level, are there any other failure cases that we have not considered and should be handling? or is there a better way of achieving the functionality described above?

like image 844
Matt Renner Avatar asked Mar 02 '17 23:03

Matt Renner


3 Answers

"PRECONDITION_FAILED - unknown delivery tag" usually happens because of double ack-ing, ack-ing on wrong channels or ack-ing messages that should not be ack-ed.

So in same case you are tying to execute basic.ack two times or basic.ack using another channel

like image 133
Gabriele Santomaggio Avatar answered Nov 02 '22 11:11

Gabriele Santomaggio


(Solution below)

Quoting Jan Grzegorowski from his blog:

If you are struggling with the 406 error message which is included in title of this post you may be interested in reading the whole story.

Problem

I was using amqplib for conneting NodeJS based messages processor with RabbitMQ broker. Everything seems to be working fine, but from time to time 406 (PRECONDINTION-FAILED) message shows up in the log:

"Error: Channel closed by server: 406 (PRECONDITION-FAILED) with message "PRECONDITION_FAILED - unknown delivery tag 1"

Solution <--

Keeping things simple:

  • You have to ACK messages in same order as they arrive to your system
  • You can't ACK messages on a different channel than that they arrive on If you break any of these rules you will face 406 (PRECONDITION-FAILED) error message.

Original answer

like image 42
Mercury Avatar answered Nov 02 '22 11:11

Mercury


It can happen if you set no-ack option of a Consumer to true that means you souldn't call ack function manually:

https://www.rabbitmq.com/amqp-0-9-1-reference.html#basic.consume.no-ack

The solution: set no-ack flag to false.

like image 6
17 revs, 13 users 59% Avatar answered Nov 02 '22 12:11

17 revs, 13 users 59%