aws-amplify / aws-sdk-android

AWS SDK for Android. For more information, see our web site:
https://docs.amplify.aws
Other
1.03k stars 550 forks source link

AWS IOT Reconnecting Issue #394

Closed yusufonderd closed 5 years ago

yusufonderd commented 6 years ago

To help us solve your problem better, please answer the following list of questions.

I'm following AndroidPubSubWebSocket sample code. Status is constantly reconnecting.

mqttManager.connect(credentialsProvider, AWSIotMqttClientStatusCallback { status, throwable ->
                runOnUiThread {
                    if (status == AWSIotMqttClientStatus.Connecting) {
                        log("Connecting...")
                    } else if (status == AWSIotMqttClientStatus.Connected) {
                        log("Connected")
                    } else if (status == AWSIotMqttClientStatus.Reconnecting) {
                        if (throwable != null) {
                            log("Connection error.")
                        }
                        log("Reconnecting")
                    } else if (status == AWSIotMqttClientStatus.ConnectionLost) {
                        if (throwable != null) {
                            log("Connection error.")
                            throwable.printStackTrace()
                        }
                        log("Disconnected")
                    } else {
                        log("Disconnected")
                    }
                }
            })

MainActivity : Connecting... AWSIotMqttManager: onFailure: connection failed. AWSIotMqttManager: schedule Reconnect attempt 0 of 10 in 4 seconds. MainActivity : Reconnecting AWSIotMqttManager: attempting to reconnect to mqtt broker AWSIotMqttManager: Reconnect failed AWSIotMqttManager: schedule Reconnect attempt 1 of 10 in 8 seconds. MainActivity : Reconnecting AWSIotMqttManager: attempting to reconnect to mqtt broker AWSIotMqttManager: Reconnect failed AWSIotMqttManager: schedule Reconnect attempt 2 of 10 in 16 seconds. MainActivity : Reconnecting...

bxpan commented 6 years ago

Does this issue also happen on newer version of Android OS ? Or is it just happening on 5.0.2 and 4.4.4?

yusufonderd commented 6 years ago

It happens different android versions. 4.4.4, 5.0.2, 7.0 . Detailed logs:

I/AWSIotMqttManager: metrics collection is enabled, username: ?SDK=Android&Version=2.6.13 I/AWSIotMqttManager: resetting reconnect attempt and retry time W/AWSIotMqttManager: onFailure: connection failed. I/AWSIotMqttManager: schedule Reconnect attempt 0 of 10 in 4 seconds. I/AWSIotMqttManager: attempting to reconnect to mqtt broker W/AWSIotMqttManager: Reconnect failed I/AWSIotMqttManager: schedule Reconnect attempt 1 of 10 in 8 seconds. I/AWSIotMqttManager: attempting to reconnect to mqtt broker W/AWSIotMqttManager: Reconnect failed I/AWSIotMqttManager: schedule Reconnect attempt 2 of 10 in 16 seconds. I/AWSIotMqttManager: attempting to reconnect to mqtt broker W/AWSIotMqttManager: Reconnect failed I/AWSIotMqttManager: schedule Reconnect attempt 3 of 10 in 32 seconds. I/AWSIotMqttManager: attempting to reconnect to mqtt broker W/AWSIotMqttManager: Reconnect failed I/AWSIotMqttManager: schedule Reconnect attempt 4 of 10 in 64 seconds. I/AWSIotMqttManager: attempting to reconnect to mqtt broker E/AWSIotMqttManager: Failed to get credentials. AmazonClientException: com.amazonaws.AmazonClientException: Unable to execute HTTP request: Read timed out at com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.java:441) at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:212) ... Caused by: java.net.SocketTimeoutException: Read timed out at com.android.org.conscrypt.NativeCrypto.SSL_read(Native Method) at com.android.org.conscrypt.OpenSSLSocketImpl$SSLInputStream.read(OpenSSLSocketImpl.java:689) at java.io.InputStream.read(InputStream.java:162) at java.io.BufferedInputStream.fillbuf(BufferedInputStream.java:142) ... I/AWSIotMqttManager: schedule Reconnect attempt 4 of 10 in 64 seconds. W/AWSIotMqttManager: Reconnect failed I/AWSIotMqttManager: schedule Reconnect attempt 5 of 10 in 64 seconds. I/AWSIotMqttManager: attempting to reconnect to mqtt broker I/AWSIotMqttManager: attempting to reconnect to mqtt broker E/AWSIotMqttManager: Exception during reconnect, exception: Connect already in progress (32110) at org.eclipse.paho.client.mqttv3.MqttAsyncClient.connect(MqttAsyncClient.java:533) at com.amazonaws.mobileconnectors.iot.AWSIotMqttManager.reconnectToSession(AWSIotMqttManager.java:903) ... I/AWSIotMqttManager: schedule Reconnect attempt 7 of 10 in 64 seconds. W/AWSIotMqttManager: Reconnect failed I/AWSIotMqttManager: schedule Reconnect attempt 7 of 10 in 64 seconds. I/AWSIotMqttManager: attempting to reconnect to mqtt broker I/AWSIotMqttManager: attempting to reconnect to mqtt broker E/AWSIotMqttManager: Exception during reconnect, exception: Connect already in progress (32110) at org.eclipse.paho.client.mqttv3.MqttAsyncClient.connect(MqttAsyncClient.java:533) at com.amazonaws.mobileconnectors.iot.AWSIotMqttManager.reconnectToSession(AWSIotMqttManager.java:903) ... I/AWSIotMqttManager: schedule Reconnect attempt 9 of 10 in 64 seconds. I/AWSIotMqttManager: attempting to reconnect to mqtt broker W/AWSIotMqttManager: Reconnect failed I/AWSIotMqttManager: schedule Reconnect attempt 9 of 10 in 64 seconds. I/AWSIotMqttManager: attempting to reconnect to mqtt broker W/AWSIotMqttManager: Reconnect failed I/AWSIotMqttManager: schedule Reconnect attempt 10 of 10 in 64 seconds. W/AWSIotMqttManager: schedule reconnect returns false E/AWSIotMqttManager: Failed to get credentials. AmazonClientException: com.amazonaws.AmazonClientException: Unable to execute HTTP request: Unable to resolve host "cognito-identity.us-east-1.amazonaws.com": No address associated with hostname at com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.java:441) at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:212) ... Caused by: java.net.UnknownHostException: Unable to resolve host "cognito-identity.us-east-1.amazonaws.com": No address associated with hostname at java.net.InetAddress.lookupHostByName(InetAddress.java:394) at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236) ... I/AWSIotMqttManager: schedule Reconnect attempt 10 of 10 in 64 seconds. W/AWSIotMqttManager: schedule reconnect returns false W/AWSIotMqttManager: Reconnect failed I/AWSIotMqttManager: schedule Reconnect attempt 11 of 10 in 64 seconds. W/AWSIotMqttManager: schedule reconnect returns false

bxpan commented 6 years ago

You are getting exception in getting credentials: E/AWSIotMqttManager: Failed to get credentials. AmazonClientException: com.amazonaws.AmazonClientException: Unable to execute HTTP request: Unable to resolve host "cognito-identity.us-east-1.amazonaws.com": No address associated with hostname Could you check that your device have actual internet connection and that your cognito pool ID as well as IoT endpoint is correct?

Thanks.

yusufonderd commented 6 years ago

Internet connection exists. And cognito pool id and endpoint correct. No problem in there. I'm getting this exception some android versions.

bxpan commented 6 years ago

Do you mean that the problem only occurs on some specific android version but not others? The SDK is not dependent on specific android OS version and should work across different android versions newer than 4.4.

I also tested on Android 7.1.1, and it was able to connect successfully.

yusufonderd commented 6 years ago

Yes problem occcurs some spesific versions. I also connect Android 7.1.1. My problem exists 4.4.4, 5.0.2 etc.

bxpan commented 6 years ago

There is no dependency on specific Android OS version for the SDK. It should work on os version newer than 4.4. Please check your settings on your 5.0.2 and perhaps try out other 5.x versions of Android OS.

erdog commented 6 years ago

We're seeing a similar problem on Android 6.0.1. The connection is fine for a while and then randomly enters a repeated reconnecting state that eventually fails our test. However, it's intermittent. We've only seen this reconnecting problem once a month for the past 6 months.

Is the problem occurring intermittently for you?

yusufonderd commented 6 years ago

Yes problem still exists.

Hospes commented 6 years ago

The same problem for me even on Android 7.1.1, I'm trying to use AWSCredentialsProvider for IoTMqttManager and it can't connect to endpoint. Credentials are good cause I'm using it for s3 and everything is fine. But mqtt manager doesn't provide any error messages and it only tries to reconnect all the time.

I'm using 2.6.15

NTCoding commented 6 years ago

I am having a similar problem - I can register a thing, create a certificate, and attach a policy as per the sample code. But when I try to connect, it just fails and works upto 10 attempts and crashes. No diagnostics or clues available.

If set Auto Reconnect to false, I am able to get diagnostics out:


02-12 14:52:40.267 21593-21705/E/RemoteCmdsAgntSvc: Error: Connection lost (32109) - java.io.EOFException
02-12 14:52:40.267 21593-21705/E/RemoteCmdsAgntSvc: Connection error: Connection lost (32109) - java.io.EOFException```
tonyteate commented 6 years ago

We're also seeing the exact same issue on Android 7.1.2, SDK version 2.6.15.

The client fails to connect initially, and remains stuck attempting to reconnect (stack trace is the same as op's). We've attempted providing credentials using both Cognito, as well as just a BasicAWSCredentials object.

trietlam commented 6 years ago

I have same error on Android 5.0.1 (Galaxy S4) The error log was not very helpful though

E/com.amazonaws.demo.androidpubsub.PubSubActivity: Connection error.
    Connection lost (32109) - java.io.EOFException
       at org.eclipse.paho.client.mqttv3.internal.CommsReceiver.run(CommsReceiver.java:146)
       at java.lang.Thread.run(Thread.java:818)
    Caused by: java.io.EOFException
       at java.io.DataInputStream.readByte(DataInputStream.java:77)
       at org.eclipse.paho.client.mqttv3.internal.wire.MqttInputStream.readMqttWireMessage(MqttInputStream.java:65)
       at org.eclipse.paho.client.mqttv3.internal.CommsReceiver.run(CommsReceiver.java:107)
       at java.lang.Thread.run(Thread.java:818) 
isha31 commented 6 years ago

Hi. Is any solution available. I am facing the same issue. Please help me! This is my log output :

`03-23 15:37:19.589 I/AWSIotMqttManager(12825): attempting to reconnect to mqtt broker 03-23 15:37:22.582 W/AWSIotMqttManager(12825): Reconnect failed 03-23 15:37:22.582 I/AWSIotMqttManager(12825): schedule Reconnect attempt 1 of 10 in 8 seconds.Thread started: #4

Thread finished: #4 The thread 0x4 has exited with code 0 (0x0). 03-23 15:37:30.589 I/AWSIotMqttManager(12825): attempting to reconnect to mqtt broker 03-23 15:37:33.686 W/AWSIotMqttManager(12825): Reconnect failed Thread started: #5 03-23 15:37:33.686 I/AWSIotMqttManager(12825): schedule Reconnect attempt 2 of 10 in 16 seconds. Thread finished: #5 The thread 0x5 has exited with code 0 (0x0). 03-23 15:37:49.702 I/AWSIotMqttManager(12825): attempting to reconnect to mqtt broker 03-23 15:37:52.746 W/AWSIotMqttManager(12825): Reconnect failed 03-23 15:37:52.746 I/AWSIotMqttManager(12825): schedule Reconnect attempt 3 of 10 in 32 seconds. Thread started: #6 Thread finished: #6 The thread 0x6 has exited with code 0 (0x0). 03-23 15:38:24.776 I/AWSIotMqttManager(12825): attempting to reconnect to mqtt broker 03-23 15:38:28.006 W/AWSIotMqttManager(12825): Reconnect failed Thread started: #7 03-23 15:38:28.006 I/AWSIotMqttManager(12825): schedule Reconnect attempt 4 of 10 in 64 seconds. 03-23 15:39:32.069 I/AWSIotMqttManager(12825): attempting to reconnect to mqtt broker 03-23 15:39:35.186 W/AWSIotMqttManager(12825): Reconnect failed Thread started: #8 03-23 15:39:35.186 I/AWSIotMqttManager(12825): schedule Reconnect attempt 5 of 10 in 64 seconds. Thread finished: #7 The thread 0x7 has exited with code 0 (0x0). 03-23 15:40:39.249 I/AWSIotMqttManager(12825): attempting to reconnect to mqtt broker 03-23 15:40:42.362 W/AWSIotMqttManager(12825): Reconnect failed 03-23 15:40:42.362 I/AWSIotMqttManager(12825): schedule Reconnect attempt 6 of 10 in 64 seconds.Thread started: #9 `

stale[bot] commented 6 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] commented 6 years ago

This issue has been automatically closed because of inactivity. Please open a new issue if are still encountering problems.

icochico commented 6 years ago

Hi,

I am experiencing the same issue. Android 7.0 and com.amazonaws:aws-android-sdk-iot:2.6.22. mqttManager tries to connect but loses the connection and then tries to reconnect in a loop. Does anybody have a solution for this?


06-15 18:58:29.590 16252-16480/? I/AWSIotMqttManager: schedule Reconnect attempt 4 of 10 in 64 seconds.
06-15 18:59:33.632 16252-16482/? I/AWSIotMqttManager: attempting to reconnect to mqtt broker
06-15 18:59:33.953 16252-16554/? I/AWSIotMqttManager: Reconnect successful
    Auto-resubscribe is enabled. Resubscribing to previous topics.
06-15 18:59:33.958 16252-16554/? W/AWSIotMqttManager: connection is Lost
06-15 18:59:33.958 16252-16554/? I/AWSIotMqttManager: schedule Reconnect attempt 5 of 10 in 64 seconds.
06-15 19:00:37.972 16252-16556/? I/AWSIotMqttManager: attempting to reconnect to mqtt broker
06-15 19:00:38.304 16252-16679/? I/AWSIotMqttManager: Reconnect successful
    Auto-resubscribe is enabled. Resubscribing to previous topics.
06-15 19:00:38.308 16252-16679/? W/AWSIotMqttManager: connection is Lost
06-15 19:00:38.309 16252-16679/? I/AWSIotMqttManager: schedule Reconnect attempt 6 of 10 in 64 seconds.
06-15 19:01:42.354 16252-16681/? I/AWSIotMqttManager: attempting to reconnect to mqtt broker
``` #
icochico commented 6 years ago

Hello everyone,

Just want to give you an update, I found a solution and I want to share it for everyone. It seems that a lot of people have experienced this problem and likely will experience it in the future. The problem lies within the fact that the AWSIotMqttManager is automatically reconnecting at every error and does not allow Exceptions to be thrown and visualized on the logcat. All it takes is to do this:

mqttManager.setAutoReconnect(false);

To be able to display Exceptions and debug the problem.

Best, Enrico

aroravinay4 commented 6 years ago

Hello folks,

The client fails to connect initially, and remains stuck attempting to reconnect.we have attempted providing credentials using both Cognito and basic AWS.

We are using "UUID.randomUUID().toString() + System.currentTimeMillis();" for generating client id.

07-03 19:45:59.840 12813-12813/com.net.pubsubandroidfinal D/com.net.pubsubandroidfinal.MainActivity: topic = hi 07-03 19:46:03.301 12813-12813/com.net.pubsubandroidfinal D/com.net.pubsubandroidfinal.MainActivity: clientId = e9a03b89-2b39-4b31-a854-6013300f810a1530627337890 07-03 19:46:03.443 12813-12813/com.net.pubsubandroidfinal I/AWSIotMqttManager: metrics collection is enabled, username: ?SDK=Android&Version=2.6.23 07-03 19:46:03.444 12813-12813/com.net.pubsubandroidfinal I/AWSIotMqttManager: resetting reconnect attempt and retry time 07-03 19:46:03.444 12813-12813/com.net.pubsubandroidfinal D/com.net.pubsubandroidfinal.MainActivity: Status = Connecting 07-03 19:46:05.673 12813-13522/com.net.pubsubandroidfinal W/AWSIotMqttManager: onFailure: connection failed. 07-03 19:46:05.673 12813-13522/com.net.pubsubandroidfinal D/com.net.pubsubandroidfinal.MainActivity: Status = Reconnecting 07-03 19:46:05.673 12813-13522/com.net.pubsubandroidfinal I/AWSIotMqttManager: schedule Reconnect attempt 0 of 10 in 4 seconds. 07-03 19:46:09.680 12813-13526/com.net.pubsubandroidfinal I/AWSIotMqttManager: attempting to reconnect to mqtt broker 07-03 19:46:11.970 12813-13561/com.net.pubsubandroidfinal W/AWSIotMqttManager: Reconnect failed 07-03 19:46:11.971 12813-13561/com.net.pubsubandroidfinal I/AWSIotMqttManager: schedule Reconnect attempt 1 of 10 in 8 seconds. 07-03 19:46:11.973 12813-13561/com.net.pubsubandroidfinal D/com.net.pubsubandroidfinal.MainActivity: Status = Reconnecting 07-03 19:46:19.982 12813-13565/com.net.pubsubandroidfinal I/AWSIotMqttManager: attempting to reconnect to mqtt broker 07-03 19:46:23.487 12813-13647/com.net.pubsubandroidfinal W/AWSIotMqttManager: Reconnect failed 07-03 19:46:23.488 12813-13647/com.net.pubsubandroidfinal I/AWSIotMqttManager: schedule Reconnect attempt 2 of 10 in 16 seconds. 07-03 19:46:23.489 12813-13647/com.net.pubsubandroidfinal D/com.net.pubsubandroidfinal.MainActivity: Status = Reconnecting 07-03 19:46:39.506 12813-13665/com.net.pubsubandroidfinal I/AWSIotMqttManager: attempting to reconnect to mqtt broker 07-03 19:46:41.914 12813-13782/com.net.pubsubandroidfinal W/AWSIotMqttManager: Reconnect failed.

Please help Us. Thanks in advance.

something15525 commented 6 years ago

Any update on this? I'm having the same issue.

something15525 commented 6 years ago

Turns out this was just bad error messaging on Paho's/the SDKs part. I was parsing the private key into a PKCS8EncodedKeySpec, instead of a RSAPrivateCrtKeySpec. This is without using Cognito, using a private key and cert.

jeremiasdsa commented 5 years ago

Same Problem

I/AWSIotMqttManager: metrics collection is enabled, username: ?SDK=Android&Version=2.8.4 I/AWSIotMqttManager: resetting reconnect attempt and retry time D/com.amazonaws.demo.androidpubsub.PubSubActivity: Status = Connecting W/AWSIotMqttManager: onFailure: connection failed. D/com.amazonaws.demo.androidpubsub.PubSubActivity: Status = ConnectionLost E/com.amazonaws.demo.androidpubsub.PubSubActivity: Connection error. MqttException (0) - java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String java.lang.String.toLowerCase()' on a null object reference at org.eclipse.paho.client.mqttv3.internal.ExceptionHelper.createMqttException(ExceptionHelper.java:38) at org.eclipse.paho.client.mqttv3.internal.ClientComms$ConnectBG.run(ClientComms.java:664) at java.lang.Thread.run(Thread.java:764) Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String java.lang.String.toLowerCase()' on a null object reference at org.eclipse.paho.client.mqttv3.internal.websocket.WebSocketHandshake.receiveHandshakeResponse(WebSocketHandshake.java:133) at org.eclipse.paho.client.mqttv3.internal.websocket.WebSocketHandshake.execute(WebSocketHandshake.java:74) at org.eclipse.paho.client.mqttv3.internal.websocket.WebSocketSecureNetworkModule.start(WebSocketSecureNetworkModule.java:77) at org.eclipse.paho.client.mqttv3.internal.ClientComms$ConnectBG.run(ClientComms.java:650) at java.lang.Thread.run(Thread.java:764) 

JoniDS commented 5 years ago

To add to this: I compiled the lib from source and printed the Throwable when reconnect never connects even if there is a network with connectivity:

2018-12-14 10:38:18.919 6622-7062/com.mqtt.test I/AWSIotMqttManager: attempting to reconnect to mqtt broker 2018-12-14 10:38:22.868 6622-7073/com.mqtt.test E/AWSIotMqttManager: Reconnect failed Connection lost (32109) - java.io.EOFException at org.eclipse.paho.client.mqttv3.internal.CommsReceiver.run(CommsReceiver.java:146) at java.lang.Thread.run(Thread.java:761) Caused by: java.io.EOFException at java.io.DataInputStream.readByte(DataInputStream.java:270) at org.eclipse.paho.client.mqttv3.internal.wire.MqttInputStream.readMqttWireMessage(MqttInputStream.java:65) at org.eclipse.paho.client.mqttv3.internal.CommsReceiver.run(CommsReceiver.java:107) at java.lang.Thread.run(Thread.java:761) 

desokroshan commented 5 years ago

@JoniDS @NTCoding @trietlam Connection lost (32109) - java.io.EOFException is caused when the connection to the client is shut down by the broker. This can happen due to a variety of reasons unrelated to the sdk such as multiple clients connecting with same clientId, unsupported QoS value for the message or if client attempts to publish/subscribe to a topic for which they don't have permission. I would recommend looking at the broker logs to see why the connection was closed by the broker.

desokroshan commented 5 years ago

@yusufonderd I was not able to reproduce the issue on Android version 5.0.2 with the latest version of the SDK. From your stack-trace, there are two different issues both of which are related to no/bad network connection on your android device/emulator :

Firstly, i.e. E/AWSIotMqttManager: Failed to get credentials. AmazonClientException: com.amazonaws.AmazonClientException: Unable to execute HTTP request: Unable to resolve host means that the application failed to get/refresh AWS Credentials as it was not able to connect to Cognito. You can add a check for reachability in your app before making call to getCredentials to ensure that you have network connectivity and avoid this error.

The second Exception from the stacktrace i.e. com.amazonaws.AmazonClientException: Unable to execute HTTP request: Read timed out means that the service took longer to respond than your configured client-side timeout. Are you setting a custom socket timeout? This can again happen due to general network issues such as stale/slow network connections.

I would recommend updating to the latest version of SDK and add a check for network connectivity before calling connect. Please let us know if the issue persists.

@Hospes @icochico We will update the sdk to log reconnection errors and pass the exception in the user callback.

@aroravinay4 @jeremiasdsa @isha31 The issue you raised is different from the op's issue. Would you mind opening a different issues for easier tracking and keeping this thread relevant to the original issue.

Thanks.

desokroshan commented 5 years ago

@Hospes @icochico We have made some changes to the SDK recently. With respect to logging and propagation of connection errors, the SDK now propagate and log connection/reconnection errors to the developer even if SDK attempts an automatic reconnect. This would help pinpoint the specific exception which caused the connection failure. Previously, even though the stacktrace may have look similar but the underlying issue could have been different. So it was difficult to root cause the connection issue from the stack trace available. Can you please try with the latest version of the SDK(2.10.0) and let me know if the issue persists?

asweeney99 commented 5 years ago

I was seeing this problem too trying to authenticate with Cognito. MQTT connection failed due to Authentication Handshake Exception. Android Version 8.0 and SDK 2.6.X Was working fine until last weekend. Couldn't understand it. I tried compiling with SDK 2.10.0 and 2.11. No luck. Then I noticed that my Android device was 5 minutes ahead of time. Changed the time back by 5 min. No connection problems. MQTT connected first time. Users should use network provided time on their local devices to stop token expiry I'm guessing. See this issue raised today #658

desokroshan commented 5 years ago

@asweeney99 Thanks for pointing that out. I understand that you were running into reconnection loop but it would be helpful if you could share the specific underlying exception. Latest version of SDK(2.10.+) should produce detailed logs with specific connection errors. Also since we are tracking this in https://github.com/aws-amplify/aws-sdk-android/issues/658 and to avoid mixing of all the different connection issues on this thread, I will add the closing-soon label back.

asweeney99 commented 5 years ago

@desokroshan Same exception as @jeremiasdsa above. Thanks for the more verbose logging but I didn't need to follow them this time.

jeremiasdsa commented 5 years ago

Hi guys, I did forget to post how I got my problem solved. So, I just needed to set the device time to automatic mode.

frankmuellr commented 5 years ago

@asweeney99, can you try @jeremiasdsa suggestion and report back your findings please?

asweeney99 commented 5 years ago

@muellerfr that's what worked for me.

frankmuellr commented 5 years ago

Looks like the issue is resolved then, and I will go ahead and close the issue. Please open a new issue if you are still encountering problems.

pradeep-techens commented 5 years ago

Hi guys, I did forget to post how I got my problem solved. So, I just needed to set the device time to automatic mode.

@jeremiasdsa can you please me know the more details. I am facing the same issue but what you mean" I just needed to set the device time to automatic mode.". Thanks in advance.

asweeney99 commented 5 years ago

@pradeep-techens He means go to your time and date settings on the phone or tablet that you are using to log in to your service. In those settings there is an option to enable automatic mode. You need to enable this setting. This will give your phone or tablet the correct time without having to update it manually.

Aqsathemes commented 5 years ago

I have also seen the same problem on Android 7.0, API 24, SDK version 2.13.4. Set the device time to automatic mode doesn't resolve the issue. Help, please!

rahulkapoor1 commented 5 years ago

There can be multiple reasons for this issues including -

  1. Cert mismatch in passed Keystore
  2. Unexpected or non unique client Id, depending on cloud side implementation
  3. Wrong pub, sub topics
Aqsathemes commented 5 years ago

@rahulkapoor1 I resolved this issue, thank you very much. The problem is in the policy, I changed it from: { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": "iot:*", "Resource": "arn:aws:iot:us-east-2:845234952158:topic/*" } ] } To this: { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "iot:Publish", "iot:Connect", "iot:Receive", "iot:Subscribe", "iot:GetThingShadow", "iot:DeleteThingShadow", "iot:UpdateThingShadow" ], "Resource": [ "*" ] } ] }

santaclawn commented 5 years ago

I was seeing this problem too trying to authenticate with Cognito. MQTT connection failed due to Authentication Handshake Exception. Android Version 8.0 and SDK 2.6.X Was working fine until last weekend. Couldn't understand it. I tried compiling with SDK 2.10.0 and 2.11. No luck. Then I noticed that my Android device was 5 minutes ahead of time. Changed the time back by 5 min. No connection problems. MQTT connected first time. Users should use network provided time on their local devices to stop token expiry I'm guessing. See this issue raised today #658

My device was ahead of actual time. Then I set it to get the time automatic from net, it actually solved the problem! Thx.

vdharmani commented 4 years ago

Getting Same issue when i re-connect the device and hit login then getting same issue in some android devices.

Unable to execute HTTP request: Hostname cognito-idp.eu-central-1.amazonaws.com not verified: certificate: sha1/zD3oLGOCYOtZiu3qfI7z4JGdlRM= DN: CN=cognito-idp.eu-central-1.amazonaws.com subjectAltNames: [cognito-idp.eu-central-1.amazonaws.com]

Thanks.

yakubpashask commented 2 years ago

@rahulkapoor1 I resolved this issue, thank you very much. The problem is in the policy, I changed it from: { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": "iot:*", "Resource": "arn:aws:iot:us-east-2:845234952158:topic/*" } ] } To this: { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "iot:Publish", "iot:Connect", "iot:Receive", "iot:Subscribe", "iot:GetThingShadow", "iot:DeleteThingShadow", "iot:UpdateThingShadow" ], "Resource": [ "*" ] } ] }

You saved my day @Aqsathemes thanks a ton!!!