Why is it that IoT Edge devices cannot connect to the IOT HUB after a month with the connection string, but can connect again after updating the string

cooldesign01 0 Reputation points
2023-05-23T01:54:07.18+00:00

IoT Edge devices cannot connect to the IOT HUB after one month of operation, but they can connect again after updating the string.The error is as follows.

2023-04-14 17:04:33.395 [azure-iot-sdk-ConnectionReconnectionTask:b3a6cdca-7daf-46c5-b307-8d1a5803edd5] ERROR [c.m.a.s.i.d.t.IotHubTransport]: Reconnection was abandoned due to encountering a non-retryable exception 
com.microsoft.azure.sdk.iot.device.exceptions.ProtocolException: Unable to establish MQTT connection
	at com.microsoft.azure.sdk.iot.device.transport.mqtt.exceptions.PahoExceptionTranslator.convertToMqttException(PahoExceptionTranslator.java:46)
	at com.microsoft.azure.sdk.iot.device.transport.mqtt.Mqtt.connect(Mqtt.java:131)
	at com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttMessaging.start(MqttMessaging.java:61)
	at com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttIotHubConnection.open(MqttIotHubConnection.java:283)
	at com.microsoft.azure.sdk.iot.device.transport.IotHubTransport.openConnection(IotHubTransport.java:1114)
	at com.microsoft.azure.sdk.iot.device.transport.IotHubTransport.singleReconnectAttempt(IotHubTransport.java:1328)
	at com.microsoft.azure.sdk.iot.device.transport.IotHubTransport.reconnect(IotHubTransport.java:1254)
	at com.microsoft.azure.sdk.iot.device.transport.IotHubTransport.handleDisconnection(IotHubTransport.java:1150)
	at com.microsoft.azure.sdk.iot.device.transport.IotHubTransport.onConnectionLost(IotHubTransport.java:336)
	at com.microsoft.azure.sdk.iot.device.transport.ReconnectionNotifier$1.run(ReconnectionNotifier.java:22)
	at java.lang.Thread.run(Thread.java:748)
Caused by: org.eclipse.paho.client.mqttv3.MqttException: MqttException
	at org.eclipse.paho.client.mqttv3.internal.ExceptionHelper.createMqttException(ExceptionHelper.java:38)
	at org.eclipse.paho.client.mqttv3.internal.ClientComms$ConnectBG.run(ClientComms.java:736)
	... 1 common frames omitted
Caused by: javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake
	at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:994)
	at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1367)
	at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1395)
	at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1379)
	at org.eclipse.paho.client.mqttv3.internal.SSLNetworkModule.start(SSLNetworkModule.java:149)
	at org.eclipse.paho.client.mqttv3.internal.ClientComms$ConnectBG.run(ClientComms.java:722)
	... 1 common frames omitted
Caused by: java.io.EOFException: SSL peer shut down incorrectly
	at sun.security.ssl.InputRecord.read(InputRecord.java:505)
	at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:975)
	... 6 common frames omitted
java.lang.IllegalStateException: Cannot add a message when the transport is closed.
	at com.microsoft.azure.sdk.iot.device.transport.IotHubTransport.addMessage(IotHubTransport.java:518)
	at com.microsoft.azure.sdk.iot.device.DeviceIO.sendEventAsync(DeviceIO.java:345)
	at com.microsoft.azure.sdk.iot.device.InternalClient.sendEventAsync(InternalClient.java:216)
	at com.microsoft.azure.sdk.iot.device.ModuleClient.sendEventAsync(ModuleClient.java:408)
	at com.microsoft.azure.sdk.iot.device.ModuleClient.sendEventAsync(ModuleClient.java:398)
	at jp.cooldesign.ems.biz.service.EdgeAzureService.sendMessageToHub(EdgeAzureService.java:152)
	at jp.cooldesign.ems.biz.task.AzureSendTask.run(AzureSendTask.java:39)
Azure IoT Edge
Azure IoT Edge
An Azure service that is used to deploy cloud workloads to run on internet of things (IoT) edge devices via standard containers.
534 questions
Azure IoT Hub
Azure IoT Hub
An Azure service that enables bidirectional communication between internet of things (IoT) devices and applications.
1,115 questions
{count} votes

1 answer

Sort by: Most helpful
  1. AshokPeddakotla-MSFT 27,386 Reputation points
    2023-06-23T15:34:55.5033333+00:00

    @cooldesign01 Are you still blocked? I'm collating the information shared above for more clarity. Please check and let us know if you have any further queries.

    When an IoT Edge device is provisioned, it is given a connection string that includes a shared access signature (SAS) token. This token has an expiration time, which is typically set to limited time. After the token expires, the device can no longer connect to the IoT hub.

    This is a security measure to prevent unauthorized access to the IoT hub. By setting an expiration time on the SAS token, you limit the amount of time that an attacker can use a stolen token to access the IoT hub.

    To resolve this issue, you can either update the connection string with a new SAS token or use the device provisioning service (DPS) to generate a new connection string.

    Please see Control access to IoT Hub using Shared Access Signatures for more details.

    Also, as Dom and Sander suggested, you can follow the SDK samples and retry mechanism.

    See Device Reconnection Sample and Retry patterns

    To update the connection string, you can use the Azure portal or the Azure CLI. Here is an example of how to update the connection string using the Azure CLI**.**If this answers your query, do click Accept Answer and Yes for was this answer helpful. And, if you have any further query do let us know.

    0 comments No comments