404104 DeviceConnectionClosedRemotely

This article describes the causes and solutions for 404104 DeviceConnectionClosedRemotely errors.

Symptoms

Symptom 1

Devices disconnect at a regular interval (every 65 minutes, for example) and you see 404104 DeviceConnectionClosedRemotely in IoT Hub resource logs. Sometimes, you also see 401003 IoTHubUnauthorized and a successful device connection event less than a minute later.

Symptom 2

Devices disconnect randomly, and you see 404104 DeviceConnectionClosedRemotely in IoT Hub resource logs.

Symptom 3

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

Cause 1

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.

Cause 2

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.

Cause 3

IoT Hub might be experiencing a transient issue. See IoT Hub internal server error cause.

Solutions

Solution 1

See 401003 IoTHubUnauthorized solution 1

Solution 2

  • 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.

Solution 3

See solutions to IoT Hub internal server errors.

Next steps

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