您现在访问的是微软AZURE全球版技术文档网站,若需要访问由世纪互联运营的MICROSOFT AZURE中国区技术文档网站,请访问 https://docs.azure.cn.

404104 DeviceConnectionClosedRemotely404104 DeviceConnectionClosedRemotely

本文介绍了 404104 DeviceConnectionClosedRemotely 错误的原因和解决方案。This article describes the causes and solutions for 404104 DeviceConnectionClosedRemotely errors.

症状Symptoms

症状 1Symptom 1

设备会按固定间隔 (每65分钟断开连接,例如) ,你会在 IoT 中心资源日志中看到 404104 个 DeviceConnectionClosedRemotelyDevices disconnect at a regular interval (every 65 minutes, for example) and you see 404104 DeviceConnectionClosedRemotely in IoT Hub resource logs. 有时,你还会看到 401003 IoTHubUnauthorized 和不到一分钟后出现的成功设备连接事件。Sometimes, you also see 401003 IoTHubUnauthorized and a successful device connection event less than a minute later.

症状 2Symptom 2

设备会随机断开连接,并且会在 IoT 中心资源日志中看到 404104 DeviceConnectionClosedRemotelyDevices disconnect randomly, and you see 404104 DeviceConnectionClosedRemotely in IoT Hub resource logs.

症状 3Symptom 3

许多设备同时断开连接时,会在连接的设备中看到一个 dip (connectedDeviceCount) 指标,并且 Azure Monitor 日志中存在比平时更多的 404104 DeviceConnectionClosedRemotely500xxx 内部错误Many devices disconnect at once, you see a dip in the Connected devices (connectedDeviceCount) metric, and there are more 404104 DeviceConnectionClosedRemotely and 500xxx Internal errors in Azure Monitor Logs than usual.

原因Causes

原因 1Cause 1

用来连接到 IoT 中心的 SAS 令牌过期,这导致 IoT 中心将设备断开连接。The SAS token used to connect to IoT Hub expired, which causes IoT Hub to disconnect the device. 当设备刷新令牌时,将重新建立连接。The connection is re-established when the token is refreshed by the device. 例如,对于 C SDK,SAS 令牌默认情况下每小时过期,这会导致定期断开连接。For example, the SAS token expires every hour by default for C SDK, which can lead to regular disconnects.

若要了解详细信息,请参阅 401003 IoTHubUnauthorized 原因To learn more, see 401003 IoTHubUnauthorized cause.

原因 2Cause 2

一些可能的原因包括:Some possibilities include:

  • 设备失去基础网络连接的时间超过了 MQTT keep alive 时长,导致远程空闲超时。The device lost underlying network connectivity longer than the MQTT keep-alive, resulting in a remote idle timeout. 每个设备的 MQTT keep-alive 设置可能不同。The MQTT keep-alive setting can be different per device.

  • 设备发送了一个 TCP/IP 级重置,但是未发送应用程序级 MQTT DISCONNECTThe device sent a TCP/IP-level reset but didn't send an application-level MQTT DISCONNECT. 从根本上说,设备突然关闭了基础套接字连接。Basically, the device abruptly closed the underlying socket connection. 有时候,此问题是由较旧版本的 Azure IoT SDK 中的 bug 导致的。Sometimes, this issue is caused by bugs in older versions of the Azure IoT SDK.

  • 设备端应用程序崩溃。The device side application crashed.

原因 3Cause 3

IoT 中心可能遇到了暂时性问题。IoT Hub might be experiencing a transient issue. 请参阅 IoT 中心内部服务器错误原因See IoT Hub internal server error cause.

解决方案Solutions

解决方案 1Solution 1

请参阅 401003 IoTHubUnauthorized 解决方案 1See 401003 IoTHubUnauthorized solution 1

解决方案 2Solution 2

  • 通过测试连接,确保设备能够正常连接到 IoT 中心。Make sure the device has good connectivity to IoT Hub by testing the connection. 如果网络不可靠或时断时续,我们不建议增大 keep-alive 值,因为这可能会导致检测(例如通过 Azure Monitor 警报)花费更长时间。If the network is unreliable or intermittent, we don't recommend increasing the keep-alive value because it could result in detection (via Azure Monitor alerts, for example) taking longer.

  • 使用最新版本的 IoT SDKUse the latest versions of the IoT SDKs.

解决方案 3Solution 3

请参阅 IoT 中心内部服务器错误的解决方案See solutions to IoT Hub internal server errors.

后续步骤Next steps

我们建议使用 Azure IoT 设备 SDK 来可靠地管理连接。We recommend using Azure IoT device SDKs to manage connections reliably. 若要了解详细信息,请参阅使用 Azure IoT 中心设备 SDK 管理连接和可靠的消息传送To learn more, see Manage connectivity and reliable messaging by using Azure IoT Hub device SDKs