# MQTT CONNACK returned with identifier rejected (0x02) or server unavailable (0x03)

- **ID:** `communication/mqtt-publish-identifier-in-use`
- **Domain:** communication
- **Category:** auth_error
- **Error Code:** `0x02`
- **Verification:** ai_generated
- **Fix Rate:** 83%

## Root Cause

MQTT broker rejected the client connection because the client identifier is already in use with a clean session not set, or the broker's connection limit has been reached.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| Mosquitto 2.0.15 | active | — | — |
| EMQX 5.3 | active | — | — |
| AWS IoT Core | active | — | — |
| Paho MQTT 1.6 | active | — | — |

## Workarounds

1. **Set the clean session flag to true in the CONNECT packet, e.g., in Paho Python: `client.connect(broker, port, keepalive=60, clean_session=True)`.** (90% success)
   ```
   Set the clean session flag to true in the CONNECT packet, e.g., in Paho Python: `client.connect(broker, port, keepalive=60, clean_session=True)`.
   ```
2. **Generate a unique client ID for each connection using a UUID or device-specific identifier, e.g., `client_id = f"device-{uuid.uuid4()}"`.** (95% success)
   ```
   Generate a unique client ID for each connection using a UUID or device-specific identifier, e.g., `client_id = f"device-{uuid.uuid4()}"`.
   ```
3. **Increase the maximum number of concurrent connections on the broker, e.g., in Mosquitto: add `max_connections 1000` to `mosquitto.conf`.** (85% success)
   ```
   Increase the maximum number of concurrent connections on the broker, e.g., in Mosquitto: add `max_connections 1000` to `mosquitto.conf`.
   ```

## Dead Ends

- **Reconnect with the same client ID repeatedly without changing anything** — The broker continues to reject the same client ID if the session is still active or limit persists. (85% fail)
- **Disable all security settings on the broker (e.g., remove authentication)** — May violate security policies and does not address the client ID conflict or connection limit. (90% fail)
- **Use a random client ID on every reconnect without setting clean session** — Random IDs may still conflict if not unique; without clean session, the broker retains state for each ID, potentially exhausting resources. (70% fail)
