-
Notifications
You must be signed in to change notification settings - Fork 75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to handle onConnectionInterrupted callback due to connection close in 24 hours #607
Comments
Copy-pasting from the other issue: The client will always reconnect in the scenario you have described. If you have CRT logs showing otherwise, please attach them. |
The logs imply that you're trying to reconnect and the SDK itself has already reconnected for you. If you remove your own reconnection logic, then what happens? Do you see that the connection is interrupted and then re-established as expected? Also, since you're using Greengrass, why not just use the Greengrass MQTT connection? It will handle message spooling and reconnection for you. https://docs.aws.amazon.com/greengrass/v2/developerguide/ipc-iot-core-mqtt.html |
|
If you remove reconnection logic, Do you see that the connection is interrupted ? If you remove reconnection logic, Do you see that the connection re-established ? why not just use the Greengrass MQTT connection? |
You should not be doing any reconnection logic at all. Just let the SDK reconnect. |
Let me try this. Also, is there a way to re-produce this scenario otherwise this will be tested in 24 hours. |
You could remove the internet connection and then add it back in a bit. That will require a reconnection. It won't necessarily be the same as the websocket timeout, but it does prove that reconnecting works. |
why not just use the Greengrass MQTT connection? |
Please get the clients logs showing that it disconnects and does not attempt to reconnect at all (or fails to reconnect). Mostly likely the issue is that you are providing static credentials that don't refresh. What is the credential provider you are using? |
Closing as internal issue was resolved with code analysis. Putting session credentials inside a static provider will lead to reconnect failures once the session credentials expire. |
This issue is now closed. Comments on closed issues are hard for our team to see. |
Describe the bug
We are creating MQTT connection(software.amazon.awssdk.crt.mqtt.MqttClientConnection) over WebSocket using IAM Role credentials. The connection gets successfully created and we are able to listen to incoming events.
However, we noticed that MQTT connection gets closed unexpectedly in 24 hours due to IOT Core limitation. And the connection does not resume automatically.
This is the code.
We receive error code:
5134
and error message "string: The connection was closed unexpectedly. for MQTT topic: <MQTT topic>
".in onConnectionInterrupted() callback method.
We tried to call
mqttSecondaryConnection.connect().get(10, TimeUnit.SECONDS);
as reconnect() inonConnectionInterrupted()
callback method but we received:java.util.concurrent.ExecutionException: software.amazon.awssdk.crt.CrtRuntimeException: MqttClientConnection.mqtt_connect: aws_mqtt_client_connection_connect failed (aws_last_error: AWS_ERROR_MQTT_ALREADY_CONNECTED(5132), The requested operation is invalid as the connection is already open.) AWS_ERROR_MQTT_ALREADY_CONNECTED(5132) at java.util.concurrent.CompletableFuture.reportGet(CompletableFuture.java:396) ~[?:?] at java.util.concurrent.CompletableFuture.get(CompletableFuture.java:2096) ~[?:?] at ...
Can anybody help, how to reconnect in this case ?
Expected Behavior
The connection should resume automatically.
Current Behavior
The connection does not resume in this case.
Reproduction Steps
Create the fresh connection after 24 hours to see the connection closure after 24 hours.
Possible Solution
No response
Additional Information/Context
No response
SDK version used
JDK17
Environment details (OS name and version, etc.)
IOT Core
The text was updated successfully, but these errors were encountered: