0x02 communication auth_error ai_generated true

MQTT CONNACK 返回标识符被拒绝 (0x02) 或服务器不可用 (0x03)

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

ID: communication/mqtt-publish-identifier-in-use

其他格式: JSON · Markdown 中文 · English
83%修复率
84%置信度
1证据数
2024-02-28首次发现

版本兼容性

版本状态引入弃用备注
Mosquitto 2.0.15 active
EMQX 5.3 active
AWS IoT Core active
Paho MQTT 1.6 active

根因分析

MQTT 代理拒绝客户端连接,因为客户端标识符已被使用且未设置清除会话,或代理的连接数已达上限。

English

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.

generic

官方文档

https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901081

解决方案

  1. 在 CONNECT 数据包中将清除会话标志设置为 true,例如在 Paho Python 中:`client.connect(broker, port, keepalive=60, clean_session=True)`。
  2. 为每个连接生成唯一的客户端 ID,使用 UUID 或设备特定标识符,例如 `client_id = f"device-{uuid.uuid4()}"`。
  3. 增加代理上的最大并发连接数,例如在 Mosquitto 中:在 `mosquitto.conf` 中添加 `max_connections 1000`。

无效尝试

常见但无效的做法:

  1. Reconnect with the same client ID repeatedly without changing anything 85% 失败

    The broker continues to reject the same client ID if the session is still active or limit persists.

  2. Disable all security settings on the broker (e.g., remove authentication) 90% 失败

    May violate security policies and does not address the client ID conflict or connection limit.

  3. Use a random client ID on every reconnect without setting clean session 70% 失败

    Random IDs may still conflict if not unique; without clean session, the broker retains state for each ID, potentially exhausting resources.