RabbitMQ PRECONDITION_FAILED - unknown delivery tag
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
RabbitMQ is a popular open-source message broker that efficiently handles complex message queuing scenarios. Like any complex system, it has specific error messages for various issues, and understanding these can help troubleshoot and optimize the message handling process. One such error is PRECONDITION_FAILED - unknown delivery tag, which can occur under certain circumstances when interacting with RabbitMQ.
Understanding of PRECONDITION_FAILED - unknown delivery tag
This error typically occurs during the process of message acknowledgment. In RabbitMQ, after a message is consumed, the consumer is expected to send an acknowledgment back to RabbitMQ. This acknowledgment is crucial because it informs RabbitMQ that a particular message has been processed and can be safely removed from the queue. The acknowledgment must be accompanied by a delivery tag.
The delivery tag is a unique identifier for the message within the channel. It is meant to be used only by the same channel that received the delivery. If the channel or the delivery tag does not match, RabbitMQ will not be able to reference the message correctly, leading to the PRECONDITION_FAILED error.
Common Scenarios Leading to This Error
- Acknowledgment from the Wrong Channel: When a message delivered to one channel is acknowledged through a different channel.
- Reused Delivery Tag: Using the same delivery tag that was either previously ACK'ed or NACK'ed.
- Invalid Session State: Attempting to acknowledge a message after the channel has entered an error state due to network issues or other errors.
- Message Requeueing: Incorrect handling during a manual message requeueing, i.e., receiving a message, it failing to process, and then incorrect acknowledgment or requeue attempt.
Examples
Here are a few examples of these scenarios in a pseudo-code setup:
Troubleshooting and Best Practices
- Always Acknowledge on the Same Channel: Ensure that the acknowledgment for a message occurs on the same channel where the message was consumed.
- Track Delivery Tags Correctly: Maintain an accurate track of delivery tags and ensure each one is used appropriately and once.
- Handle Errors Gracefully: Implement logic to handle channel and connection errors appropriately to reset state correctly.
Summary Table of Key Error Triggers and Solutions
| Scenario | Problem | Solution |
| Wrong Channel ACK | Acknowledgment sent through a different channel | Always ACK on the same channel that received the message. Close and reopen channel if mixed up |
| Reuse of Delivery Tag | Same delivery tag reused for multiple ACKs | Maintain unique delivery tags, reset if needed when requeueing or after errors |
| Incorrect Requeueing | Not resetting delivery tag or channel after error | Implement thorough error handling around messaging operations |
Conclusion
Understanding the specifics behind the PRECONDITION_FAILED - unknown delivery tag error in RabbitMQ can significantly aid in troubleshooting and ensuring reliable message processing systems. Proper handling of channels and delivery tags, along with robust error management, are crucial components for leveraging RabbitMQ effectively in distributed architectures.
Related reading

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.