Skip to content

[Bug Report] ClassCastException: class com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttIotHubConnection cannot be cast to class com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsIotHubConnection #1853

Description

@claudiadahl

Context

  • OS and version used: amazoncorretto:25-alpine-jdk (Dockerfile)
  • Java runtime used: 25.0.2
  • SDK version used: 2.5.1

Description of the issue

We have some DeviceClients - using the IotHubClientProtocol.MQTT - that connects, sends and close their connection afterwards.

In case the IoTHub is not available at the moment that DeviceClients try to reconnect to it causing the following exception:

java.lang.ClassCastException: class com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttIotHubConnection cannot be cast to class com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsIotHubConnection (com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttIotHubConnection and com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsIotHubConnection are in unnamed module of loader org.springframework.boot.loader.launch.LaunchedClassLoader @3c27f72)
	at com.microsoft.azure.sdk.iot.device.transport.IotHubTransport.singleDeviceReconnectAttemptAsync(IotHubTransport.java:1464)
	at com.microsoft.azure.sdk.iot.device.transport.IotHubTransport.reconnect(IotHubTransport.java:649)
	at com.microsoft.azure.sdk.iot.device.transport.IotHubReconnectTask.run(IotHubReconnectTask.java:94)
	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:545)
	at java.base/java.util.concurrent.FutureTask.runAndReset(FutureTask.java:369)
	at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:310)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1090)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:614)
	at java.base/java.lang.Thread.run(Thread.java:1474)

Since the IoTHub is seldom out of order we do not see that exception very often. But when it is there are a lot of devices that try to reconnect causing a lot of exceptions for a very short time range.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions