Skip to content
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

Closed
1 task done
codegame6 opened this issue Oct 20, 2020 · 7 comments
Closed
1 task done
Labels
documentation This is a problem with documentation. p2 This is a standard priority issue

Comments

@codegame6
Copy link

codegame6 commented Oct 20, 2020

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.

  1. When Internet is not available
    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)

  1. When endpoint URL is incorrect
    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)

  1. With invalid certificate (certificate is not valid)
    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)
    ....

  1. With incorrect certificate (certificate is not allowed for connection)
    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

  1. With incorrect Root CA
    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.

@codegame6 codegame6 added guidance Question that needs advice or information. needs-triage This issue or PR still needs to be triaged. labels Oct 20, 2020
@jmklix
Copy link
Member

jmklix commented Oct 20, 2020

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.

@jmklix jmklix removed the needs-triage This issue or PR still needs to be triaged. label Oct 20, 2020
@jmklix jmklix self-assigned this Oct 20, 2020
@jmklix jmklix added the closing-soon This issue will automatically close in 5 days unless further comments are made. label Oct 20, 2020
@codegame6
Copy link
Author

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.
I can see an error in exception as I mentioned on the above logs. Is it possible to share the error number as well or some document saying error in each condition? So that AWS IoT Device SDK users can know the correct status and take necessary action.

@github-actions github-actions bot removed the closing-soon This issue will automatically close in 5 days unless further comments are made. label Oct 21, 2020
@codegame6
Copy link
Author

Is there anything already available or can be added?

@jmklix
Copy link
Member

jmklix commented Feb 10, 2021

No, there is nothing currently available. But I do agree it is something that can be added to help diagnose connection failures.

@jmklix jmklix added documentation This is a problem with documentation. and removed guidance Question that needs advice or information. labels Feb 10, 2021
@jmklix jmklix removed their assignment Dec 16, 2021
@codegame6
Copy link
Author

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.

@jmklix jmklix added the p2 This is a standard priority issue label Nov 7, 2022
@jmklix
Copy link
Member

jmklix commented Dec 13, 2023

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

Value Hex Reason Code name Description
0 0x00 Success The connection is accepted.
128 0x80 Unspecified error The server does not wish to reveal the reason for the failure, or none of the other reason codes apply.
133 0x85 Client Identifier not valid The client identifier is a valid string but is not allowed by the server.
134 0x86 Bad User Name or Password The server does not accept the user name or password specified by the client.
135 0x87 Not authorized The client is not authorized to connect.
144 0x90 Topic Name invalid The Will Topic Name is correctly formed but is not accepted by the server.
151 0x97 Quota exceeded An implementation or administrative imposed limit has been exceeded.
155 0x9B QoS not supported The server does not support the QoS set in Will QoS.

@jmklix jmklix closed this as completed Dec 13, 2023
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation This is a problem with documentation. p2 This is a standard priority issue
Projects
None yet
Development

No branches or pull requests

2 participants