This article describes the causes and solutions for 404104 DeviceConnectionClosedRemotely errors.
Devices disconnect at a regular interval (every 65 minutes, for example) and you see 404104 DeviceConnectionClosedRemotely in IoT Hub diagnostic logs. Sometimes, you also see 401003 IoTHubUnauthorized and a successful device connection event less than a minute later.
Devices disconnect randomly, and you see 404104 DeviceConnectionClosedRemotely in IoT Hub diagnostic logs.
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. For example, the SAS token expires every hour by default for C SDK, which can lead to regular disconnects.
To learn more, see 401003 IoTHubUnauthorized cause.
Some possibilities include:
The device lost underlying network connectivity longer than the MQTT keep-alive, resulting in a remote idle timeout. The MQTT keep-alive setting can be different per device.
The 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. Sometimes, this issue is caused by bugs in older versions of the Azure IoT SDK.
The device side application crashed.
IoT Hub might be experiencing a transient issue. See IoT Hub internal server error cause.
Make sure the device has good connectivity to IoT Hub by testing the connection. 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.
Use the latest versions of the IoT SDKs.
We recommend using Azure IoT device SDKs to manage connections reliably. To learn more, see Manage connectivity and reliable messaging by using Azure IoT Hub device SDKs