Skip to content

Is it possible to know reason when connection to server is failed? #105

Closed
@codegame6

Description

@codegame6

Confirm by changing [ ] to [x] below:

  • I've searched for previous similar issues and didn't find any solution

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.

Activity

added
guidanceQuestion that needs advice or information.
needs-triageThis issue or PR still needs to be triaged.
on Oct 20, 2020
jmklix

jmklix commented on Oct 20, 2020

@jmklix
Member

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.

removed
needs-triageThis issue or PR still needs to be triaged.
on Oct 20, 2020
self-assigned this
on Oct 20, 2020
added
closing-soonThis issue will automatically close in 5 days unless further comments are made.
on Oct 20, 2020
codegame6

codegame6 commented on Oct 21, 2020

@codegame6
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.

removed
closing-soonThis issue will automatically close in 5 days unless further comments are made.
on Oct 21, 2020
codegame6

codegame6 commented on Nov 3, 2020

@codegame6
Author

Is there anything already available or can be added?

jmklix

jmklix commented on Feb 10, 2021

@jmklix
Member

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

added
documentationThis is a problem with documentation.
and removed
guidanceQuestion that needs advice or information.
on Feb 10, 2021
removed their assignment
on Dec 16, 2021
codegame6

codegame6 commented on Feb 1, 2022

@codegame6
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.

added
p2This is a standard priority issue
on Nov 7, 2022

4 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationThis is a problem with documentation.p2This is a standard priority issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @jmklix@codegame6

        Issue actions

          Is it possible to know reason when connection to server is failed? · Issue #105 · aws/aws-iot-device-sdk-java-v2