aws-amplify / aws-sdk-ios

AWS SDK for iOS. For more information, see our web site:
https://aws-amplify.github.io/docs
Other
1.68k stars 885 forks source link

Error connecting to AWS services, kCFURLErrorCannotFindHost = -1003 #167

Closed Kumuluzz closed 9 years ago

Kumuluzz commented 9 years ago

We have been working on an iOS project which makes use of the official AWS SDK for iOS (version 2.017) and Cognito Sync SDK for iOS (version 1.0.8). Both of these have been installed using the dependency management system CocoaPods.


Our project interacts with the Cognito and SQS services. All iOS devices post messages to the same queue (outbound queue). The individual iOS device will then read from a specified queue only for that iOS device (inbound queue nr1, nr2, nr3...).

We have encountered the error kCFURLErrorCannotFindHost (code -1003) from time to time while reading the inbound queues. We have not yet found the root of this issue, so we are not able to systematically recreate it. Sometimes it happens on 3G, sometimes on WiFi, other times there can go days before it reoccurs.

UPDATE: The error seems to occur mainly over 3G when changing location. So it happens whenever the app tries to connect to the server again through a new 3G antenna.

This error has occurred both when connecting to Cognito and to the SQS service. A screenshot of the error can be seen below when trying to connected to the SQS: aws_forum_post_1003

When the error occurs, then it will continue to happen for around 5-10 minutes before it disappears. No changes are done to the code and the location of the device is not changed. It seems to disappear naturally after this timeframe.

We have a theory that the error is connected to the NSURLConnection class. We will continue to try and pinpoint the root of the error by examining the AWS SDK. Our current lead is focusing on the “keepalive” parameter.

It is important to notice, this error does not seem to be related to only the AWS Cloud. We have New Relic implemented for the same iOS project which experiences the same error.


We are looking for a way to recover from this error and thought that it should be done from the AWS SDK. Would you have some advice for resetting the NSURLConnection when this error occurs? We will happy to try your suggestions by making changes to the AWS SDK.

yosuke-matsuda commented 9 years ago

Based on your description, it appears to be an unstable network issue. Do you know if the DNS in your environment is working as expected?

When a request fails due to a bad network connection, you can check the content of task.error in the continueWithBlock block and retry as needed. It is also possible to update AWSCognitoSyncRequestRetryHandler to let the SDK handle it. However, handling the retry in the continueWithBlock block may be a better option since it can be more flexible.

Kumuluzz commented 9 years ago

We also considered that it was due to an unstable network, but it only seems to affect our app and not others. If we open any other app (such as the Mail app from Apple, Facebook or LinkedIn), then they will update without problems when trying to refresh.

We have already implemented the continueWithBlock, this is where we have the log in the previous post from. And it was by examining task.error we found the error to be kCFURLErrorCannotFindHost.


In the continueWithBlock we have tried to recursively call the same method which calls the receiveMessage method on a AWSSQSReceiveMessageRequest, but with no luck. The same error continues to occur for the following 5-10 minutes. For now we are simply notifying our controller which displays a UIAlertController with an error message explaining the user to try again after 5 minutes.

yosuke-matsuda commented 9 years ago

All of the services you listed are high traffic websites, and it makes sense that the DNS has fresh records for them. In order to isolate the DNS issue, can you convert sqs.eu-west-1.amazonaws.com to an IP address and use it to see if it resolves the issue when you see the error? Amazon SQS allows HTTP access (Amazon Cognito only allows HTTPS), and use HTTP instead of HTTPS in order to avoid a certificate error. You can manipulate _URL here to change the URL.

Please use the IP address to access AWS services only for testing purposes, and do not ship your app with embedded IP addresses since they can change any time.

Kumuluzz commented 9 years ago

We have been trying for many days now to recreate the error systematically before trying to solve it, but still without luck. The error happens less frequently now, which is good, but also bad since it makes debugging harder.

We have now implemented static IP addresses instead of the dynamic endpoints. The code now looks as follows:

...
} else if (_serviceType == AWSServiceSimpleDB && _regionType == AWSRegionUSEast1) {
    _URL = [NSURL URLWithString:[NSString stringWithFormat:@"%@://sdb.amazonaws.com", HTTP_Type]];

/* CUSTOM CODE START */
} else if (_serviceType == AWSServiceSQS && _regionType == AWSRegionEUWest1) {
    NSLog(@"AWS, custom, SQS, EUWest1");
    _URL = [NSURL URLWithString:[NSString stringWithFormat:@"http://178.236.6.180"]]; // IP instead of sqs.eu-west-1.amazonaws.com
} else if (_serviceType == AWSServiceCognitoIdentityBroker && _regionType == AWSRegionEUWest1) {
    NSLog(@"AWS, custom, cognito identity, EUWest1");
    _URL = [NSURL URLWithString:[NSString stringWithFormat:@"https://176.32.110.59"]]; // IP instead of cognito-identity.eu-west-1.amazonaws.com
/* CUSTOM CODE END */

} else {
...

We will keep this thread updated if anything new happens related to this -1003 error.


We are still far away from releasing the app and when the time comes then we will make sure that we do not ship it with embedded IP addresses. Thanks for the heads up!

yosuke-matsuda commented 9 years ago

Please let us know if you can reproduce the issue with the latest SDK. Thanks.