Bug 42864 - [Cycle 7] "System.Net.WebException: Error: NameResolutionFailure" on second web request to certain raw IP addresses with HttpClient
Summary: [Cycle 7] "System.Net.WebException: Error: NameResolutionFailure" on second w...
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: 4.6.0 (C8)
Assignee: Marek Safar
: 42850 (view as bug list)
Depends on: 41782
  Show dependency tree
Reported: 2016-07-28 00:45 UTC by Brendan Zagaeski (Xamarin Team, assistant)
Modified: 2016-08-17 17:48 UTC (History)
7 users (show)

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


Description Brendan Zagaeski (Xamarin Team, assistant) 2016-07-28 00:45:47 UTC
[Cycle 7] "System.Net.WebException: Error: NameResolutionFailure" on second web request to certain raw IP addresses with HttpClient

This is a follow-up to Bug 41782.  At least when using HttpClient as in the code example below, `ServicePoint.get_HostEntry()` [1] gets called 2 separate times, once for each request.  On the second time, `host` is non-null and `HasTimedOut` is true, so `get_HostEntry()` returns `null` rather than returning the non-null `host`.

[1] https://github.com/mono/mono/blob/d35b5d218894e15cec84273d77cf4a61985edb5f/mcs/class/System/System.Net/ServicePoint.cs#L348

## Steps to replicate

Replace the IP address in the following program with a "bad" IP address that hits the problem and run the program.

using System.Net.Http;

namespace ConsoleApp1
    class MainClass
        public static void Main(string[] args)

        public static void DoRequest()
            var httpClient = new HttpClient();

            var responseTask = httpClient.GetAsync("");
            var response = responseTask.Result;

## Regression status: regression in Cycle 7

BAD:  Mono 4.6.0 (mono-4.6.0-branch/37dea728)      "C8"
BAD:  Mono 4.4.2 (mono-4.4.0-branch-c7sr1/b430435) "C7SR1"
GOOD: Mono 4.2.4 (explicit/71b88f3)                "C6SR4"

## BAD Results

The second call to `DoRequest()` fails:

> Unhandled Exception:
> System.AggregateException: One or more errors occurred. ---> System.Net.WebException: Error: NameResolutionFailure

## GOOD Results

The app runs to completion without error.
Comment 2 Brendan Zagaeski (Xamarin Team, assistant) 2016-07-28 00:50:31 UTC
*** Bug 42850 has been marked as a duplicate of this bug. ***
Comment 5 Marek Safar 2016-08-16 13:26:47 UTC
Fixed in master and Mono 4.6

Notice (2018-05-21): bugzilla.xamarin.com will be switching to read-only mode on Thursday, 2018-05-25 22:00 UTC.

Please join us on Visual Studio Developer Community and GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs and copy them to the new locations as needed for follow-up. The See Also field on each Bugzilla bug will be updated with a link to its new location when applicable.

After Bugzilla is read-only, if you have new information to add for a bug that does not yet have a matching issue on Developer Community or GitHub, you can create a follow-up issue in the new location. Copy and paste the title and description from this bug, and then add your new details. You can get a pre-formatted version of the title and description here:

In special cases you might also want the comments:

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.

Note You need to log in before you can comment on or make changes to this bug.