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

Add .NET 4.7.1 Networking known issue 534719 #580

Merged
merged 2 commits into from
Dec 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# ServicePoint.ConnectionLimit default behavior with loopback changed unexpectedly

## Symptoms
The limit for HTTP connections per endpoint is controlled by the `ServicePointManager.DefaultConnectionLimit` property.
This value defaults to 2. In the .NET Framework 4.7 and earlier versions, the limit applied only to non-loopback
addresses such as http://www.microsoft.com. For loopback addresses such as http://localhost, the limit for connections
was always int.MaxValue (2,147,483,647) unless changed by calling the `ServicePoint.ConnectionLimit` API.

In the .NET Framework 4.7.1 when using HttpClient APIs, the connection limit for loopback addresses now matches the limit
for non-loopback addresses. Thus, the default limit is 2. This can cause applications to run slower or hang when
doing multiple, parallel, requests to the http://localhost addresses.

Here is code that shows the problem:

```c#
using System;
using System.Net;
using System.Net.Http;

namespace ConsoleApp
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine($"ServicePointManager.DefaultConnectionLimit: {ServicePointManager.DefaultConnectionLimit}");

var uriLoopback = new Uri("http://localhost");
var uriExternal = new Uri("http://www.microsoft.com");

Console.WriteLine("Before using HttpClient APIs");
ServicePoint spLoopback = ServicePointManager.FindServicePoint(uriLoopback);
Console.WriteLine($"{uriLoopback.AbsoluteUri}, ConnectionLimit (should be {int.MaxValue}): {spLoopback.ConnectionLimit}");

ServicePoint spExternal = ServicePointManager.FindServicePoint(uriExternal);
Console.WriteLine($"{uriExternal.AbsoluteUri}, ConnectionLimit (should be {ServicePointManager.DefaultConnectionLimit}): {spExternal.ConnectionLimit}");

Console.WriteLine("Use HttpClient APIs");
var client = new HttpClient();
try
{
HttpResponseMessage response = client.GetAsync(uriLoopback).Result;
}
catch (Exception)
{
// Ignore any network error since there is probably not a loopback server present.
}

Console.WriteLine("After using HttpClient APIs");

// BUG - due to the bug in .NET Framework 4.7.1, the ConnectionLimit for this loopback ServicePoint is changed
// unexpectedly.
Console.WriteLine($"{uriLoopback.AbsoluteUri}, ConnectionLimit (should be {int.MaxValue}): {spLoopback.ConnectionLimit}");
}
}
}
```

## Cause
Changes in .NET Framework 4.7.1 to the `System.Net.Http.HttpClientHandler` class caused this problem.

## Resolution
To work around the problem using HttpClient APIs, you can use the following code to increase the connection limit.
This code should be added before calling any HttpClient APIs.

```c#
ServicePointManager.DefaultConnectionLimit = 20; // Actual value should be based on your requirements.
```

Note: This will also change the limits for non-loopback addresses.

## More information
We will fix this problem in a future .NET Framework Quality Rollup release.
1 change: 1 addition & 0 deletions releases/net471/dotnet471-known-issues.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ This document lists the known issues that you may experience after you install t
- [521954 - BCL - CultureAwareComparer with ignore casing serialized on previous versions of .NET Framework does not correctly deserialize on .NET Framework 4.7.1](https://github.com/Microsoft/dotnet/blob/master/releases/net471/KnownIssues/521954%20-%20BCL%20CultureAwareComparer%20with%20ignore%20casing%20on%20serialized%20on%20previous%20versions%20of%20.NET%20do%20not%20correctly%20deserialize%20on%20.NET%204.7.1.md)
- [517815 - BCL - Applications making heavy use of System.Diagnostics.StackTrace or Exception.StackTrace might run more slowly on the .NET Framework 4.7.1](https://github.com/Microsoft/dotnet/blob/master/releases/net471/KnownIssues/517815-BCL%20Applications%20making%20heavy%20use%20of%20System.Diagnostics.StackTrace%20might%20run%20more%20slowly%20on%20.NET%204.7.1.md)
- [523633 - Setup - Application crashes occur when running on the .NET Framework 4.7.1 after upgrading from Windows 10 Anniversary Update to Windows 10 Creators Update](https://github.com/Microsoft/dotnet/blob/master/releases/net471/KnownIssues/523633%20-%20Setup%20-%20OS%20upgrade%20to%20Windows%2010%20gets%20the%20product%20in%20bad%20state.md)
- [534719 - Networking - ServicePoint.ConnectionLimit default behavior with loopback changed unexpectedly](https://github.com/Microsoft/dotnet/blob/master/releases/net471/KnownIssues/534719-Networking%20ServicePoint.ConnectionLimit%20default%20behavior%20with%20loopback%20changed%20unexpectedly.md)