Posts / A story about slow NuGet package browsing

In Rider, we have integration tests which interact with Also, we have an internal service which monitors the performance of these tests. Two days ago, I noticed that some of these tests sometimes are running for too long. For example, nuget_NuGetTest_shouldUpgradeVersionForDotNetCore usually takes around 10 sec. However, in some cases, it takes around 110 sec, 210 sec, or 310 sec:

It looks very suspicious and increases the whole test suite duration. Also, our dashboard with performance degradations contains only such tests and some real degradations (which are introduced by the changes in our codebase) can go unnoticed. So, my colleagues and I decided to investigate it.

First of all, we decided to look at the logs:

Information   GET
Information An error was encountered when fetching
  'GET'. The request will now be retried.
The HTTP request to 'GET'
  has timed out after 100000ms.
Information   GET
Information   OK 1090ms

In this test, we are trying to get TOP 10 NuGet packages from The code calls NuGet.Client API which constructs the url and send a HTTP request. The server doesn’t respond in 100'000ms, NuGet terminates this request by timeout and retries it.

We decided to write a simple small repro based on HttpClient which reproduces the issue:

for (int i = 0; i < 100; i++)
    using (var client = new HttpClient { Timeout = TimeSpan.FromSeconds(10000) })
        Console.Write("Request #" + (i + 1).ToString("000") + ": ");
        var sw = Stopwatch.StartNew();
            var r = await client.GetAsync(
        catch (Exception e)
            Console.Write("FAIL                 .");
        Console.WriteLine($" Time: {sw.Elapsed.TotalSeconds:0.000} sec");

Surprisingly, with Timeout = TimeSpan.FromSeconds(10000) almost all of the request are successful. On Windows, it produces the following distribution:

It’s very important to create a new instance of HttpClient for the each iteration: otherwise, the connection will be reused, and we will not get such a picture.

In the picture, we have a multimodal distribution with following levels:

A remark: on my machine, the first attempt uses TLSv1.2, the second attempt uses TLSv1.1, the third attempt uses TLSv1. A screenshot from Wireshark for the ~250sec case:

We tried it on our local machines and double checked it on an Azure VM:

This problem affects (sometimes) different IDEs with NuGet Package Manager: it may take up to several minutes before it displays the search results. That’s how it looks in Visual Studio:

That’s how it looks in Visual Studio for Mac:

It’s hard to reproduce this issue in Rider because we are using a persistent local cache of search results:

Currently, the problem is reproduced on ( and (

Since it’s a server-side problem and we can’t fix it locally, we created an issue on GitHub: NuGet/Home#6921 (moved to NuGet/NuGetGallery#5899).

Update. A remark about the code snippet. In the first version of the repro, I used a single HttpClient instance for all requests. In this case, the first request fails in ~30% cases, other requests are successful because the connection is already established. From the practical point of view, it means that user can get hanged NuGet Package Manager in VS only once after startup. However, in this case, it’s hard to investigate the problem because it’s very unstable. Thus, the code snippet creates a new HttpClient instance each time on purpose. So, it’s very easy to reproduce the problem.

Update 2018-05-11. The issue is fixed.