-
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
Is it possible to know reason when connection to server is failed? #105
Comments
You won't be able to see the disconnect reason on the client side, because in the MQTT protocol the connection is dropped without sending a reason to the client. You can check the CloudWatch logs to see the cause of the connection failure. To enable CloudWatch logs look here. |
Some of the information is important for client side for user experience. Based on this information android application take required action like if certificates are invalid then it can show an indication to the user and it should not retry to connect but if it is something to do with the network then it can retry in the background and there can be other use-cases as well. |
Is there anything already available or can be added? |
No, there is nothing currently available. But I do agree it is something that can be added to help diagnose connection failures. |
Is it possible to make getErrorCode public from MqttException or provide a different approach to provide error codes? This will help us to take appropriate action based on the error codes. Currently, all the errors are reported as MqttException with different error strings which cannot be used to take actions for different errors. |
MQTT 5 has added reason codes to its connection events. This will allow you to get a better idea of why the connection is failing. Check out the AWS MQTT documentation and our MQTT 5 sample for more info about this. Below are some of the reason codes that you can see in MQTT 5 CONNACK Reason Codes
|
|
Confirm by changing [ ] to [x] below:
Platform/OS/Hardware/Device
What are you running the sdk on?
Android
Describe the question
I am using java-v2 SDK for Android.
To establish an MQTT connection I am using the connect API of MqttClientConnection.
When the connection fails, it provides ExecutionException but is there any way by which we can know the error number or some other detail by which we can know the cause of connection error like not able to connect to the server, certificate error or any other error. So, it can be used to take appropriate action like try to recover error if possible or show user appropriate error on UI.
I have opened below issue but was not able to provide the requested detail in time and it is closed so I am creating new one.
#99
Below are some logs for different conditions.
W/System.err: java.util.concurrent.ExecutionException: software.amazon.awssdk.crt.mqtt.MqttException: System call failure
W/System.err: at java.util.concurrent.CompletableFuture.reportGet(CompletableFuture.java:359)
W/System.err: at java.util.concurrent.CompletableFuture.get(CompletableFuture.java:1921)
....
W/System.err: Caused by: software.amazon.awssdk.crt.mqtt.MqttException: System call failureW/System.err: at software.amazon.awssdk.crt.mqtt.MqttClientConnection.onConnectionComplete(MqttClientConnection.java:142)
W/System.err: java.util.concurrent.ExecutionException: software.amazon.awssdk.crt.mqtt.MqttException: TLS (SSL) negotiation failed
W/System.err: at java.util.concurrent.CompletableFuture.reportGet(CompletableFuture.java:359)
W/System.err: at java.util.concurrent.CompletableFuture.get(CompletableFuture.java:1921)
....
W/System.err: Caused by: software.amazon.awssdk.crt.mqtt.MqttException: TLS (SSL) negotiation failed
W/System.err: at software.amazon.awssdk.crt.mqtt.MqttClientConnection.onConnectionComplete(MqttClientConnection.java:142)
W/System.err: software.amazon.awssdk.crt.CrtRuntimeException: TlsContext.tls_ctx_new: Failed to create new aws_tls_ctx (aws_last_error: AWS_IO_TLS_CTX_ERROR(1033), Failed to create tls context)
W/System.err: at software.amazon.awssdk.crt.io.TlsContext.tlsContextNew(Native Method)
W/System.err: at software.amazon.awssdk.crt.io.TlsContext.(TlsContext.java:34)
W/System.err: at software.amazon.awssdk.crt.io.ClientTlsContext.(ClientTlsContext.java:36)
W/System.err: at software.amazon.awssdk.iot.AwsIotMqttConnectionBuilder.build(AwsIotMqttConnectionBuilder.java:401)
....
W/System.err: java.util.concurrent.ExecutionException: software.amazon.awssdk.crt.mqtt.MqttException: Mqtt operation interrupted by connection shutdown
W/System.err: at java.util.concurrent.CompletableFuture.reportGet(CompletableFuture.java:359)
W/System.err: at java.util.concurrent.CompletableFuture.get(CompletableFuture.java:1921)
....
W/System.err: Caused by: software.amazon.awssdk.crt.mqtt.MqttException: Mqtt operation interrupted by connection shutdown
W/System.err: java.util.concurrent.ExecutionException: software.amazon.awssdk.crt.mqtt.MqttException: TLS (SSL) negotiation failed
W/System.err: at java.util.concurrent.CompletableFuture.reportGet(CompletableFuture.java:359)
W/System.err: at java.util.concurrent.CompletableFuture.get(CompletableFuture.java:1921)
....
W/System.err: Caused by: software.amazon.awssdk.crt.mqtt.MqttException: TLS (SSL) negotiation failed
W/System.err: at software.amazon.awssdk.crt.mqtt.MqttClientConnection.onConnectionComplete(MqttClientConnection.java:142)
Please let me know in case more information required.
The text was updated successfully, but these errors were encountered: