# MQTT CONNACK: packet identifier already in use

- **ID:** `communication/mqtt-packet-identifier-in-use`
- **Domain:** communication
- **Category:** protocol_error
- **Verification:** ai_generated
- **Fix Rate:** 76%

## Root Cause

The MQTT client sent a PUBLISH or SUBSCRIBE packet with a packet identifier that is already in use for an outstanding acknowledgment, violating the MQTT protocol specification.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| Mosquitto 2.0.15 | active | — | — |
| Paho MQTT 1.3.12 | active | — | — |
| EMQX 5.0 | active | — | — |

## Workarounds

1. **Implement a proper packet identifier manager that reuses IDs only after acknowledgment or timeout. Example in C using Paho: `MQTTAsync_setCallbacks(client, NULL, connlost, msgarrvd, onDeliveryComplete)` and track IDs via a hash set.** (76% success)
   ```
   Implement a proper packet identifier manager that reuses IDs only after acknowledgment or timeout. Example in C using Paho: `MQTTAsync_setCallbacks(client, NULL, connlost, msgarrvd, onDeliveryComplete)` and track IDs via a hash set.
   ```
2. **Increase `max_inflight_messages` in broker config (e.g., Mosquitto: `max_inflight_messages 20`) to reduce identifier reuse pressure.** (70% success)
   ```
   Increase `max_inflight_messages` in broker config (e.g., Mosquitto: `max_inflight_messages 20`) to reduce identifier reuse pressure.
   ```

## Dead Ends

- **** — Disabling QoS entirely (QoS 0) avoids identifiers but loses delivery guarantees. (50% fail)
- **** — Manually incrementing packet IDs without tracking acknowledgments still causes collisions. (80% fail)
- **** — Restarting the broker clears state but doesn't fix the client's identifier management logic. (70% fail)
