RabbitMQ PRECONDITION_FAILED – unknown delivery tag

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?

Source: stackoverflow-php