Bug 18613 - Error: NameResolutionFailure on web service call to https
Summary: Error: NameResolutionFailure on web service call to https
Status: RESOLVED ANSWERED
Alias: None
Product: Android
Classification: Xamarin
Component: BCL Class Libraries ()
Version: 4.12.0
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Jonathan Pryor
URL:
Depends on:
Blocks:
 
Reported: 2014-03-27 09:58 UTC by Dylan
Modified: 2017-06-27 00:18 UTC (History)
3 users (show)

Tags: bb
Is this bug a regression?: ---
Last known good build:


Attachments
app output (27.81 KB, text/plain)
2014-03-27 09:58 UTC, Dylan
Details
app output with stack trace (28.56 KB, text/plain)
2014-03-30 14:45 UTC, Dylan
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED ANSWERED

Description Dylan 2014-03-27 09:58:42 UTC
Created attachment 6420 [details]
app output

We are constantly getting this error on Xamarin.Android 4.12.2 lately and it has also been brought to my attention by clients.

When we start our app we call an initialize web service. The exact address of this is https://prod.affinionmobile.com/ams/

Often now days we are returned with an Error: NameResolutionFailure. A retry then normally succeeds. It is not consistent nor is it always reproduceable, but I have been trying everything to mitigate this error and I have come up short. The exact same code works flawlessly on Xamarin.iOS and Windows Phone. 

Before all calls I now run this code to try help resolve what looks to be a DNS problem:
                System.Uri uri = new System.Uri(InitializationController.GetWebServiceURL());
                var ip = Dns.GetHostEntry(uri.Host);

However this does not help and the error still persists. Does this have anything to do with https? Is there something else I need to do to try and resolve this issue? Must I build in logic to retry the web service for a 2nd time if the first time failed? 

Attached is the application output for when the service runs. You'll notice a "prod.affinionmobile.com resolved!" output and then not too far below will be the NameResolutionFailure. 

Could this maybe not be the problem?
[Mono] AOT module 'Mono.Security.dll.so' not found: dlopen failed: library "/data/data/com.Conference.MD/lib/Mono.Security.dll.so" not found

Any further insight or assistance will be greatly appreciated.
Comment 1 Jonathan Pryor 2014-03-27 10:18:12 UTC
> Could this maybe not be the problem?

No.

> Error: NameResolutionFailure

What would be helpful is if you print Exception.ToString() instead of Exception.Message, so that the full stack trace is provided.

That said, it's possible (probable) that you're running out of file descriptors; see Bug #15135 and https://bugzilla.xamarin.com/show_bug.cgi?id=13750#c16.

If this is the issue you're seeing (and I suspect it is), the workaround is for you to call GC.Collect() "occasionally" in order to ensure that the Sockets are GC'd and the associated file descriptors are freed.
Comment 2 Dylan 2014-03-27 11:08:40 UTC
Alright I am going to catch the stack traces for you. 

We normally notice this problem as soon as the app loads. Surely I shouldn't have to call GC.Collect() that early in the life cycle? I'll also try and let you know.
Comment 3 Dylan 2014-03-30 14:44:38 UTC
Got a stack trace. Full trace and app output logged. 

System.Net.WebException: Error: NameResolutionFailure
  at System.Net.HttpWebRequest.EndGetResponse (IAsyncResult asyncResult) [0x00000] in <filename unknown>:0 
  at System.Threading.Tasks.TaskFactory`1[System.Net.WebResponse].InnerInvoke (System.Threading.Tasks.TaskCompletionSource`1 tcs, System.Func`2 endMethod, IAsyncResult l) [0x00000] in <filename unknown>:0 


Something strange happening with the HttpWebRequest? As I said, before doing any web request call on Android I check that there is an active connection, followed by Dns.GetHostEntry(uri.Host). There should not no reason that a NameResolutionFailure happens after these checks. 

Btw my manifest does definitely include the Internet permission.
Comment 4 Dylan 2014-03-30 14:45:03 UTC
Created attachment 6436 [details]
app output with stack trace
Comment 5 Jonathan Pryor 2014-03-31 15:49:55 UTC
Is this a Debug or a Release app? Release apps don't get INTERNET permission by default, and the iNTERNET permission is required in order to access network resources. (Debug apps get INTERNET permission so that the debugger can attach.)

I doubt this is the case, as that would impact _all_ network connections, and you state that a "retry then normally succeeds," which implies that the INTERNET permission is present.

Would it be possible for you to provide a repro?
Comment 6 Dylan 2014-03-31 17:48:39 UTC
Happens for debug and release. Internet permission is definitely present. 

I'll try my best to make a repro. Right now I've used Dns.GetHostEntry to rather call the web service via the IP Address instead of the hostname.

A side note: I get Error: NameResolutionFailure on Xamarin.iOS when in airplane mode and trying to call the web service.
Comment 7 Jonathan Pryor 2014-03-31 22:34:34 UTC
>  I get Error: NameResolutionFailure on Xamarin.iOS when in airplane
> mode and trying to call the web service

"Airplane mode" == "No network connection" (unless Wi-Fi is separately enabled), so this makes perfect sense: you get NameResolutionFailure because there's no operating network stack to perform the name resolution request.
Comment 8 Dylan 2014-04-24 11:12:10 UTC
May be related to: https://bugzilla.xamarin.com/show_bug.cgi?id=15135
Comment 9 Koby 2014-07-18 12:48:42 UTC
This bug still exists in my app using Android 4.14
Comment 10 Chris Hardy [MSFT] 2017-06-26 17:59:04 UTC
Thank you for taking the time to submit this report. Are you are still experiencing the issue after updating to the latest version of Xamarin.Android? If so, please reopen this report with an attached reproduction or steps to reproduce the issue. Thanks!