Bug 41782 - [Cycle 7] "System.Net.WebException: Error: NameResolutionFailure" when attempting web requests with certain raw IP addresses
Summary: [Cycle 7] "System.Net.WebException: Error: NameResolutionFailure" when attemp...
Status: VERIFIED FIXED
Alias: None
Product: Class Libraries
Classification: Mono
Component: System (show other bugs)
Version: 4.4.0 (C7)
Hardware: PC Mac OS
: High major
Target Milestone: (C7SR0)
Assignee: Marek Safar
URL:
: 41571 41699 41876 41938 41985 (view as bug list)
Depends on: 41571
Blocks: 42864
  Show dependency tree
 
Reported: 2016-06-14 02:19 UTC by Brendan Zagaeski (Xamarin Team, assistant)
Modified: 2016-09-12 15:36 UTC (History)
16 users (show)

Tags: BZRC7S1_C6SR4S1, DefectEscapeReview_Done
Is this bug a regression?: Yes
Last known good build: Mono 4.2.4 (71b88f3)

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 GitHub or Developer Community 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:
VERIFIED FIXED

Description Brendan Zagaeski (Xamarin Team, assistant) 2016-06-14 02:19:00 UTC
[Cycle 7] "System.Net.WebException: Error: NameResolutionFailure" when attempting web requests with certain raw IP addresses

This is a public bug to track the status of non-public Bug 41571.




## Regression status: regression in Cycle 7

BAD:  Mono 4.4.0 (5995f74)
GOOD: Mono 4.2.4 (71b88f3)




## Steps to replicate


1. Replace the IP address in the following 2 lines with a "bad" IP address that shows the problem:

var request = WebRequest.CreateHttp ("http://127.0.0.1");
request.GetResponse ();


2. Run the request.




## Results

The request fails:

> System.Net.WebException: Error: NameResolutionFailure
>   at System.Net.HttpWebRequest.EndGetResponse (IAsyncResult asyncResult) <0x27cf0d0 + 0x00187> in <filename unknown>:0 
>   at System.Net.HttpWebRequest.GetResponse () <0x27c74c0 + 0x0004c> in <filename unknown>:0 
>   at ConsoleApp1.MainClass.Main (System.String[] args) <0x6eeec8 + 0x0001b> in <filename unknown>:0 



If you set the IDE to break whenever a System.Exception is thrown, you can get a bit more interesting stack trace for a "System.Net.Sockets.SocketException":

>   at System.Net.Dns.Error_11001(string hostName) in /private/tmp/source-mono-4.4.0-c7-baseline/bockbuild-mono-4.4.0-c7-baseline/profiles/mono-mac-xamarin/build-root/mono-x86/mcs/class/System/System.Net/Dns.cs:292
>   at System.Net.Dns.GetHostByAddressFromString(string address, bool parse) in /private/tmp/source-mono-4.4.0-c7-baseline/bockbuild-mono-4.4.0-c7-baseline/profiles/mono-mac-xamarin/build-root/mono-x86/mcs/class/System/System.Net/Dns.cs:361
>   at System.Net.Dns.GetHostEntry(System.Net.IPAddress address) in /private/tmp/source-mono-4.4.0-c7-baseline/bockbuild-mono-4.4.0-c7-baseline/profiles/mono-mac-xamarin/build-root/mono-x86/mcs/class/System/System.Net/Dns.cs:388
>   at System.Net.Dns.GetHostEntry(string hostNameOrAddress) in /private/tmp/source-mono-4.4.0-c7-baseline/bockbuild-mono-4.4.0-c7-baseline/profiles/mono-mac-xamarin/build-root/mono-x86/mcs/class/System/System.Net/Dns.cs:378
>   at System.Net.ServicePoint.get_HostEntry() in /private/tmp/source-mono-4.4.0-c7-baseline/bockbuild-mono-4.4.0-c7-baseline/profiles/mono-mac-xamarin/build-root/mono-x86/mcs/class/System/System.Net/ServicePoint.cs:352
>   at System.Net.WebConnection.Connect(System.Net.HttpWebRequest request) in /private/tmp/source-mono-4.4.0-c7-baseline/bockbuild-mono-4.4.0-c7-baseline/profiles/mono-mac-xamarin/build-root/mono-x86/mcs/class/System/System.Net/WebConnection.cs:152
>   at System.Net.WebConnection.InitConnection(System.Net.HttpWebRequest state) in /private/tmp/source-mono-4.4.0-c7-baseline/bockbuild-mono-4.4.0-c7-baseline/profiles/mono-mac-xamarin/build-root/mono-x86/mcs/class/System/System.Net/WebConnection.cs:703
>   at System.Net.WebConnection.AnonymousMethod__0(System.Net.HttpWebRequest state) in /private/tmp/source-mono-4.4.0-c7-baseline/bockbuild-mono-4.4.0-c7-baseline/profiles/mono-mac-xamarin/build-root/mono-x86/mcs/class/System/System.Net/WebConnection.cs:106
>   at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(System.Threading.QueueUserWorkItemCallback state) in /private/tmp/source-mono-4.4.0-c7-baseline/bockbuild-mono-4.4.0-c7-baseline/profiles/mono-mac-xamarin/build-root/mono-x86/external/referencesource/mscorlib/system/threading/threadpool.cs:1307
>   at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Threading.QueueUserWorkItemCallback state, bool preserveSyncCtx) in /private/tmp/source-mono-4.4.0-c7-baseline/bockbuild-mono-4.4.0-c7-baseline/profiles/mono-mac-xamarin/build-root/mono-x86/external/referencesource/mscorlib/system/threading/executioncontext.cs:957
>   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Threading.QueueUserWorkItemCallback state, bool preserveSyncCtx) in /private/tmp/source-mono-4.4.0-c7-baseline/bockbuild-mono-4.4.0-c7-baseline/profiles/mono-mac-xamarin/build-root/mono-x86/external/referencesource/mscorlib/system/threading/executioncontext.cs:904
>   at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem() in /private/tmp/source-mono-4.4.0-c7-baseline/bockbuild-mono-4.4.0-c7-baseline/profiles/mono-mac-xamarin/build-root/mono-x86/external/referencesource/mscorlib/system/threading/threadpool.cs:1284
>   at System.Threading.ThreadPoolWorkQueue.Dispatch() in /private/tmp/source-mono-4.4.0-c7-baseline/bockbuild-mono-4.4.0-c7-baseline/profiles/mono-mac-xamarin/build-root/mono-x86/external/referencesource/mscorlib/system/threading/threadpool.cs:857
>   at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback() in /private/tmp/source-mono-4.4.0-c7-baseline/bockbuild-mono-4.4.0-c7-baseline/profiles/mono-mac-xamarin/build-root/mono-x86/external/referencesource/mscorlib/system/threading/threadpool.cs:1212
Comment 2 Brendan Zagaeski (Xamarin Team, assistant) 2016-06-14 02:31:41 UTC
## Additional information

- I attempted to replicate the problem without depending on a customer's endpoint.  I set a VM to have exactly the same "bad" IP address and ran an HTTP server on it.  Unfortunately, that setup worked _without_ error.  So the problem might require some other detail of server configuration or network routing that was not present in that simpler local setup.

- I also tested another 20 common IP addresses for various websites, but so far I haven't found any additional addresses that hit this issue.  I don't have any guesses about what makes certain IP addresses "special" in the context of this bug.
Comment 3 Brendan Zagaeski (Xamarin Team, assistant) 2016-06-14 02:32:33 UTC
*** Bug 41699 has been marked as a duplicate of this bug. ***
Comment 4 Brendan Zagaeski (Xamarin Team, assistant) 2016-06-14 02:41:49 UTC
## Possible workarounds

- Use domain names rather than IP addresses for the web requests.

- If possible, try an alternate IP address for the same resource.  With a little bit of luck, the problem might not affect the second IP address.




## Downgrading

If needed, you can also downgrade temporarily as described under "Updating and downgrading" on the Cycle 7 forum announcement:

http://forums.xamarin.com/discussion/68358/stable-release-cycle-7-feature-release/p1
Comment 7 Brendan Zagaeski (Xamarin Team, assistant) 2016-06-15 16:18:13 UTC
For thorough cross-referencing, I'll record that this issue is now included in the known issues section of the releases notes for Xamarin.iOS, Xamarin.Android, and Xamarin.Mac.:


- https://developer.xamarin.com/releases/ios/xamarin.ios_9/xamarin.ios_9.8/#Known_Issues

- https://developer.xamarin.com/releases/android/xamarin.android_6/xamarin.android_6.1/#Known_Issues

- https://developer.xamarin.com/releases/mac/xamarin.mac_2/xamarin.mac_2.8/#Releases
Comment 8 Marek Safar 2016-06-16 13:42:31 UTC
*** Bug 41571 has been marked as a duplicate of this bug. ***
Comment 9 Marek Safar 2016-06-16 17:20:41 UTC
Fixed in master and Mono 4.5.

A fix for Mono 4.4 is waiting in service release queue.
Comment 10 Marek Safar 2016-06-16 19:18:43 UTC
*** Bug 41876 has been marked as a duplicate of this bug. ***
Comment 11 Mohit Kheterpal 2016-06-17 14:42:44 UTC
To verify this issue, I am using the sample provided in its duplicate bug 41571.

Now, I am not getting error mentioned in bug description, But I am getting following error : 

Error - There was an error on processing web request: Status code 405(MethodNotAllowed): Method Not Allowed

Not sure, is this expected behaviour for the sample attached in Bug 41571 or is this different issue.

Could you please confirm ?

Thanks
Comment 12 Brendan Zagaeski (Xamarin Team, assistant) 2016-06-17 15:55:38 UTC
Yes, that is the expected behavior as described in non-public Bug 41571, Comment 2.  I will mark this bug as "verified" accordingly.  Thanks for the test!
Comment 13 Brendan Zagaeski (Xamarin Team, assistant) 2016-06-17 17:01:03 UTC
*** Bug 41938 has been marked as a duplicate of this bug. ***
Comment 14 Marek Safar 2016-06-20 07:24:39 UTC
*** Bug 41985 has been marked as a duplicate of this bug. ***
Comment 15 Ace Olszowka 2016-07-27 20:13:11 UTC
We're still seeing this as of Xamarin.Android 6.1.1 (7bd2aac)/Xamarin 4.1.13 (34a92cd); however it only appears on the SECOND request. I'm opening a new private case with a repo'ing project.
Comment 16 Jean-Baptiste 2016-07-28 15:29:55 UTC
we also have that issue. 
file : https://github.com/mono/mono/blob/e233950c6e237843c1658d386e3347c7b78f5c37/mcs/class/System/System.Net/ServicePoint.cs

line 363 -> the if must be TRUE is this is a IP address in all cases
Comment 17 Brendan Zagaeski (Xamarin Team, assistant) 2016-07-28 15:32:48 UTC
@Jean-Baptiste, that issue has been filed in its own follow-up bug linked to this one under the "Blocks" field: Bug 42864.