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

AmazonClientException crashes app on bad network #556

Closed
NightOwlCoder opened this issue Oct 25, 2018 · 24 comments
Closed

AmazonClientException crashes app on bad network #556

NightOwlCoder opened this issue Oct 25, 2018 · 24 comments
Assignees
Labels
bug Something isn't working iot Issues with the AWS Android SDK for Internet of Things (IoT) pending-community-response Issue is pending response from the issue requestor

Comments

@NightOwlCoder
Copy link

Hey there,
using com.amazonaws:aws-android-sdk-iot:2.7.6 to connect to my service, is crashing my app.

Full stack is below, but basically I see that this call:

https://github.com/aws/aws-sdk-android/blob/master/aws-android-sdk-iot/src/main/java/com/amazonaws/mobileconnectors/iot/AWSIotMqttManager.java#L720

running in an anonymous thread will not catch AmazonClientException.

Off course, no matter how I call it, this will always crash.

    fun load()
    {
        // MQTT client IDs are required to be unique per AWS IoT account.
        clientId = MiscUtil.getAndroidId()

        topic = "xyz123"

        // Initialize the AWS Cognito credentials provider
        credentialsProvider = CognitoCachingCredentialsProvider(App.app, COGNITO_POOL_ID, IOT_REGION)

        // MQTT Client
        mqttManager = AWSIotMqttManager(clientId, IOT_ENDPOINT)
    }

Above method is called under a try/catch, not depicted above.

Can we fix this?

Full stack follow:

com.amazonaws.AmazonClientException: Unable to execute HTTP request: Unable to resolve host "cognito-identity.us-west-2.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)
	at com.amazonaws.services.cognitoidentity.AmazonCognitoIdentityClient.invoke(AmazonCognitoIdentityClient.java:566)
	at com.amazonaws.services.cognitoidentity.AmazonCognitoIdentityClient.getCredentialsForIdentity(AmazonCognitoIdentityClient.java:389)
	at com.amazonaws.auth.CognitoCredentialsProvider.populateCredentialsWithCognito(CognitoCredentialsProvider.java:782)
	at com.amazonaws.auth.CognitoCredentialsProvider.startSession(CognitoCredentialsProvider.java:694)
	at com.amazonaws.auth.CognitoCredentialsProvider.getCredentials(CognitoCredentialsProvider.java:465)
	at com.amazonaws.auth.CognitoCachingCredentialsProvider.getCredentials(CognitoCachingCredentialsProvider.java:485)
	at com.amazonaws.auth.CognitoCachingCredentialsProvider.getCredentials(CognitoCachingCredentialsProvider.java:77)
	at com.amazonaws.mobileconnectors.iot.AWSIotMqttManager$1.run(AWSIotMqttManager.java:720)
	at java.lang.Thread.run(Thread.java:761)
Caused by: java.net.UnknownHostException: Unable to resolve host "cognito-identity.us-west-2.amazonaws.com": No address associated with hostname
	at java.net.Inet6AddressImpl.lookupHostByName(Inet6AddressImpl.java:95)
	at java.net.Inet6AddressImpl.lookupAllHostAddr(Inet6AddressImpl.java:74)
	at java.net.InetAddress.getAllByName(InetAddress.java:757)
	at com.android.okhttp.internal.Network$1.resolveInetAddresses(Network.java:29)
	at com.android.okhttp.internal.http.RouteSelector.resetNextInetSocketAddress(RouteSelector.java:187)
	at com.android.okhttp.internal.http.RouteSelector.nextProxy(RouteSelector.java:156)
	at com.android.okhttp.internal.http.RouteSelector.next(RouteSelector.java:98)
	at com.android.okhttp.internal.http.HttpEngine.createNextConnection(HttpEngine.java:372)
	at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:355)
	at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:273)
	at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:474)
	at com.android.okhttp.internal.huc.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:126)
	at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getOutputStream(HttpURLConnectionImpl.java:257)
	at com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.getOutputStream(DelegatingHttpsURLConnection.java:218)
	at com.android.okhttp.internal.huc.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java)
	at com.amazonaws.http.UrlHttpClient.writeContentToConnection(UrlHttpClient.java:162)
	at com.amazonaws.http.UrlHttpClient.execute(UrlHttpClient.java:75)
	at com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.java:371)
	... 10 more
java.net.UnknownHostException: Unable to resolve host "cognito-identity.us-west-2.amazonaws.com": No address associated with hostname
	at java.net.Inet6AddressImpl.lookupHostByName(Inet6AddressImpl.java:95)
	at java.net.Inet6AddressImpl.lookupAllHostAddr(Inet6AddressImpl.java:74)
	at java.net.InetAddress.getAllByName(InetAddress.java:757)
	at com.android.okhttp.internal.Network$1.resolveInetAddresses(Network.java:29)
	at com.android.okhttp.internal.http.RouteSelector.resetNextInetSocketAddress(RouteSelector.java:187)
	at com.android.okhttp.internal.http.RouteSelector.nextProxy(RouteSelector.java:156)
	at com.android.okhttp.internal.http.RouteSelector.next(RouteSelector.java:98)
	at com.android.okhttp.internal.http.HttpEngine.createNextConnection(HttpEngine.java:372)
	at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:355)
	at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:273)
	at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:474)
	at com.android.okhttp.internal.huc.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:126)
	at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getOutputStream(HttpURLConnectionImpl.java:257)
	at com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.getOutputStream(DelegatingHttpsURLConnection.java:218)
	at com.android.okhttp.internal.huc.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java)
	at com.amazonaws.http.UrlHttpClient.writeContentToConnection(UrlHttpClient.java:162)
	at com.amazonaws.http.UrlHttpClient.execute(UrlHttpClient.java:75)
	at com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.java:371)
	at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:212)
	at com.amazonaws.services.cognitoidentity.AmazonCognitoIdentityClient.invoke(AmazonCognitoIdentityClient.java:566)
	at com.amazonaws.services.cognitoidentity.AmazonCognitoIdentityClient.getCredentialsForIdentity(AmazonCognitoIdentityClient.java:389)
	at com.amazonaws.auth.CognitoCredentialsProvider.populateCredentialsWithCognito(CognitoCredentialsProvider.java:782)
	at com.amazonaws.auth.CognitoCredentialsProvider.startSession(CognitoCredentialsProvider.java:694)
	at com.amazonaws.auth.CognitoCredentialsProvider.getCredentials(CognitoCredentialsProvider.java:465)
	at com.amazonaws.auth.CognitoCachingCredentialsProvider.getCredentials(CognitoCachingCredentialsProvider.java:485)
	at com.amazonaws.auth.CognitoCachingCredentialsProvider.getCredentials(CognitoCachingCredentialsProvider.java:77)
	at com.amazonaws.mobileconnectors.iot.AWSIotMqttManager$1.run(AWSIotMqttManager.java:720)
	at java.lang.Thread.run(Thread.java:761)
@mutablealligator mutablealligator self-assigned this Oct 25, 2018
@mutablealligator mutablealligator added the iot Issues with the AWS Android SDK for Internet of Things (IoT) label Oct 25, 2018
@mutablealligator
Copy link
Contributor

@NightOwlCoder Sorry for the inconvenience caused. Can you check if the emulator when you were running your app/tests switched from one network to the other? I have encountered this issue when my emulator switches from one network to the other. If I restart the emulator and connect to the new network again, the app/tests work fine.

If I understand correctly, you are invoking connect method in the AWSIotMqttManager. The connect method accepts a callback and if there is an exception raised, the SDK invoke the callback. Have you passed in a valid callback? See https://github.com/aws/aws-sdk-android/blob/master/aws-android-sdk-iot/src/main/java/com/amazonaws/mobileconnectors/iot/AWSIotMqttManager.java#L742

@mutablealligator mutablealligator added the pending-community-response Issue is pending response from the issue requestor label Oct 25, 2018
@NightOwlCoder
Copy link
Author

Hey @kvasukib , yes I do have a callback which is never called.

The code you pointed to
catch (final MqttException e) {

catches MqttException, and what I'm seeing on the crash log is AmazonClientException, isn't that the reason?

@mutablealligator
Copy link
Contributor

Got it. AmazonClientException is a runtime exception. The SDK throws this exception when the SDK cannot handle an error scenario at runtime. You can catch this exception in your app and take corresponding action. Nonetheless, we will add more error handling mechanisms in the AWSIotMqttManager.

@NightOwlCoder
Copy link
Author

I can't catch that, as it is under a thread you guys create.

@mutablealligator
Copy link
Contributor

@NightOwlCoder Apologies for the confusion. We will address this by catching the AmazonClientException and invoking the StatusCallback passed into the connect method.

@mutablealligator mutablealligator added bug Something isn't working and removed pending-community-response Issue is pending response from the issue requestor labels Oct 29, 2018
@NightOwlCoder
Copy link
Author

Hey there, any way for me getting an early release to test this?

My app keeps crashing, and I would like to help to get a faster fix.

@NightOwlCoder
Copy link
Author

Hey @kvasukib, any feedback on this?

My app keeps crashing and I really need at least a workaround...

Looks like every time there is a network hiccup it can't survive.

@mutablealligator
Copy link
Contributor

@NightOwlCoder Sorry for the delay. I have added exception handling and passing it back to the client status callback. This change will be released in the next revision of the SDK.

@mutablealligator
Copy link
Contributor

mutablealligator commented Nov 2, 2018

@NightOwlCoder This has been fixed in 2.7.7 version of the SDK. Please upgrade to the latest and let us know if you have any feedback. You can download the SDK from this page: https://aws.amazon.com/mobile/resources/. The maven artifact for 2.7.7 should be available soon.

UPDATE: The maven artifact is available now.

@mutablealligator mutablealligator added closing soon Issue will auto-close if there is no additional activity within 7 days. pending-community-response Issue is pending response from the issue requestor labels Nov 2, 2018
@stale stale bot removed the closing soon Issue will auto-close if there is no additional activity within 7 days. label Nov 2, 2018
@NightOwlCoder
Copy link
Author

Hey there @kvasukib , I have installed this on 3 of our devices in QA and will report back once 24h has passed.

Thanks for the quick turn around.

@zhouxuemeng1988
Copy link

I have been having this problem for a year, thank you, and finally solved it.

@frankmuellr frankmuellr added the closing soon Issue will auto-close if there is no additional activity within 7 days. label Nov 7, 2018
@mutablealligator
Copy link
Contributor

Thank you @zhouxuemeng1988 for the feedback. Apologies for our delay in fixing it. Please let us know how your app testing goes and we welcome your feedback.

@zhouxuemeng1988
Copy link

zhouxuemeng1988 commented Nov 8, 2018

Response migrated to #567

@mutablealligator
Copy link
Contributor

@zhouxuemeng1988 The issue you raised is different from the original issue. This happens when the network is not reachable. You can add a check for network reachability in your app before making a network call. Can you open a new issue for this and we can discuss there?

@mutablealligator mutablealligator self-assigned this Nov 8, 2018
@zhouxuemeng1988
Copy link

@zhouxuemeng1988 The issue you raised is different from the original issue. This happens when the network is not reachable. You can add a check for network reachability in your app before making a network call. Can you open a new issue for this and we can discuss there?

com.amazonaws.AmazonClientException: Unable to execute HTTP request: Unable to resolve host "cognito-identity.us-west-2.amazonaws.com": No address associated with hostname at
This looks like the same bug

@frankmuellr frankmuellr removed the closing soon Issue will auto-close if there is no additional activity within 7 days. label Nov 12, 2018
@tajchert
Copy link

tajchert commented Nov 12, 2018

I'm still having that issue on 2.7.7 SDK.
EDIT: Same for 2.8.0

Crash log:

com.amazonaws.AmazonClientException: Unable to execute HTTP request: Unable to resolve host "cognito-identity.eu-central-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)
at com.amazonaws.services.cognitoidentity.AmazonCognitoIdentityClient.invoke(AmazonCognitoIdentityClient.java:566)
at com.amazonaws.services.cognitoidentity.AmazonCognitoIdentityClient.getId(AmazonCognitoIdentityClient.java:448)
at com.amazonaws.auth.AWSAbstractCognitoIdentityProvider.getIdentityId(AWSAbstractCognitoIdentityProvider.java:172)
at com.amazonaws.auth.AWSEnhancedCognitoIdentityProvider.refresh(AWSEnhancedCognitoIdentityProvider.java:76)
at com.amazonaws.auth.CognitoCredentialsProvider.startSession(CognitoCredentialsProvider.java:678)
at com.amazonaws.auth.CognitoCredentialsProvider.getCredentials(CognitoCredentialsProvider.java:465)
at com.amazonaws.auth.CognitoCachingCredentialsProvider.getCredentials(CognitoCachingCredentialsProvider.java:485)
at com.amazonaws.auth.CognitoCachingCredentialsProvider.getCredentials(CognitoCachingCredentialsProvider.java:77)
at com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient.invoke(AmazonDynamoDBClient.java:5200)
at com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient.scan(AmazonDynamoDBClient.java:2481)
at com.amazonaws.mobileconnectors.dynamodbv2.dynamodbmapper.DynamoDBMapper.scan(DynamoDBMapper.java:2264)
at com.amazonaws.mobileconnectors.dynamodbv2.dynamodbmapper.DynamoDBMapper.scan(DynamoDBMapper.java:2228)

@mutablealligator
Copy link
Contributor

@tajchert Please use #567 for your issue as it is different from #556.

@tajchert
Copy link

tajchert commented Nov 12, 2018

It doesn't look like #567 as it mentions Read timeout in exception, and mine as well this one ( #556 ) mentions:
AmazonClientException: Unable to execute HTTP request: Unable to resolve host "cognito-identity.eu-central-1.amazonaws.com": No address associated with hostname and have same stacktrace.
Which seems like correct fit, or maybe both of them have similar origin (?)
Anyway I moved to 567 as requested, hopefully we can handle offline/slow network without crashing whole app.

@NightOwlCoder
Copy link
Author

@kvasukib hey there, is there a way for me to increase log level?

@frankmuellr frankmuellr removed the pending-community-response Issue is pending response from the issue requestor label Nov 20, 2018
@GiovanniVisentiniST
Copy link

GiovanniVisentiniST commented Nov 21, 2018

Response migrated to #588

@minbi
Copy link
Contributor

minbi commented Nov 21, 2018

Hi @GiovanniVisentini ,

Can you open a different issue? You do have a similar stacktrace, but since you are using Pinpoint the fix will be else where in the code. This thread is getting crowded by different code fixes.

Thanks

@GiovanniVisentiniST
Copy link

@minbi ok sorry, I open issue #588

@desokroshan
Copy link
Contributor

@NightOwlCoder SDK uses Apache Commons Logging library(JCL) if it is present in the classpath else it uses android.util.Log.
Using JCL: JCL is a wrapper for popular logging APIs such as Log4J, logback etc. If your app does not take a dependency on any of these, common logging library defaults to java.util.logging package present in JDK. Configuration of the behavior of the JCL ultimately depends upon the logging toolkit(log4j, logback etc.) being used. Please refer the documentation for the chosen logging system to adjust the log level. If you are defaulting to java.util.logging package, you can change log level as follows :

Add logging.properties file to res/raw and add following to onCreate of the MainActivity

logger = Logger.getLogger(PubSubActivity.class.getName());
InputStream raw = getResources().openRawResource(R.raw.logging);
LogManager lManager = LogManager.getLogManager();
lManager.readConfiguration(raw);

Using Android Log : There is no way to change log level for entire SDK in this case. However as a workaround to change log levels for debugging purposes you can change it for a specific tag with the following command:
adb shell setprop log.tag.<YOUR_LOG_TAG> <LEVEL>

@desokroshan desokroshan added the pending-community-response Issue is pending response from the issue requestor label Dec 25, 2018
@minbi
Copy link
Contributor

minbi commented Dec 31, 2018

Hi,

We are closing this issue because the original issue was resolved. Please feel free to open a new issue if the problem persists. We ask this because closed issues are not actively monitored.

Thanks

@minbi minbi closed this as completed Dec 31, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working iot Issues with the AWS Android SDK for Internet of Things (IoT) pending-community-response Issue is pending response from the issue requestor
Projects
None yet
Development

No branches or pull requests

8 participants