PRECONDITION_FAILED - unknown delivery tag 1
The channel is closed and the consumer reconnects. Annoying, but harmless? Not quite: the error has a side effect that turns into duplicate processing. Measured on RabbitMQ 4.3.6.
A delivery tag is a number the broker gives each message it hands to a channel. It is only valid on that channel, and only until the message is acknowledged. An ack, nack or reject with a tag the channel does not know closes the channel. We triggered it three ways:
| What the code did | Result |
|---|---|
| acked the same message twice | unknown delivery tag |
fetched with auto_ack=True, then acked | unknown delivery tag: with auto-ack there is nothing left to ack |
| acked on a different channel of the same connection | unknown delivery tag: tags are per channel |
In frameworks the double ack usually comes from two places acking the same message: the framework acks after the handler returns, and the handler acks itself as well. Spring AMQP's default acknowledge mode, for example, acks for you; a manual channel.basicAck in the listener on top of that is a second ack.
Closing the channel returns every message that is still unacknowledged on it. We fetched three messages, acked the first two, then acked the first one again:
unknown delivery tag 1;redelivered=true.The consumer that reconnects gets it again. If the first copy is still being processed, or finishes and acks into a closed channel, the message is processed twice. With prefetch 50, it is up to 49 messages each time.