Solving flaky dotnet restore issue only on Docker — Failed to retrieve information
I’ve got stuck for a couple of days to solve this issue. When I build a Dockerfile, at the part of the dotnet restore
I encountered this issue. However, On my colleague’s PC, it works perfectly. Only my PC didn’t work. At first it didn’t work both on WSL2 and Docker for Windows, I do nothing special, however, suddenly WSL2 works fine. I had totally no idea. I search a lot on the internet, I try a several workaround, however, all of them didn’t work. Some people looks has the same issue, however, no one looks solve the exact issue as me. However, I have it again! When I help to configure my colleague’s pc, it happens again. However, I finally figure out this issue. I’ll share the workaround.
Issue
The issue is looks like this. dotnet restore
fails.
I add the dotnet restore -v diag
option to more diagnose. It looks fail to download the JSON file like this `https://dotnetmyget.blob.core.windows.net/artifacts/aspnetcore-dev/nuget/v3/flatcontainer/system.reflection.emit.lightweight/index.json`. However, when I curl it from my container, it perfectly works. Also ping and traceroute works on the container.
The error message, looks like Connection refused
. And the remote party has closed the transport stream
. That means remote host has closed the connection.
I’m not sure if you can repro it, however, on my machine, I can use this Dockerfile to repro.
I’ve done several workaround. All of them doesn’t work.
- Add resources to Docker for Windows (4CPU 8GMEM)
- Google DNS
- Exclude Hyper-V, Docker on the Windows Defender
- Googling
Clue
However, I noticed one thing when I watch the TaskManager. When I start the dotnet restore, at first, it is fine. My PC receive data with 200Mbps, however, in the middle of the execution, it suddenly down to 10Kbps, and I can see a lot of connection issues.
I was curious what is happened. I use White Shark to find the issue. I found Surious Retransmission
That means it causes packet loss.
Why it losses the packet? For example, the Maximum request rate per storage account is 20,000 requests per second. I’m not sure if it is the case.
Solution
However, I’m sure it is throttling
issue. I suppose that we should send request slower. How can I limit it? It might have a better way, however, I try simple measure. I limit the Docker resources likes. I make it SLOW!
Works!
I bought a super fast pc since the covid-19 is coming. That was the root cause. lol.
Then, why my WLS2 works? Probably, I limited the memory of the WSL2 and hasn’t done a lot of WSL2 network is slow workaround.
Conclusion
This issue is throttling issue for me. However, Probably better solution might be there. Please comment your idea, if you know it.
Additional Info (10/29/2020)
I found a blog post for configuring WSL2 memory and CPU.
The other cool solution is
dotnet restore --disable-parallel
That option is not throttling option, however, it limit the parallel NuGet restore for each csproj file. If you can modify the Dockerfile, you can use this measure.
Also this configuration might ultimate solution for this. Thank you Shibayan!
The document looks old, however, you can see the pull request that is already merged.
It looks happens for the private NuGet repository. I use maxHttpRequest
It might be the best way.
<?xml version="1.0" encoding="utf-8"?><configuration><config><add key="maxHttpRequest" value="16" /></config><packageSources><add key="nuget.org" value="https://www.nuget.org/api/v2/" /><add key="azure_app_service" value="https://www.myget.org/F/azure-appservice/api/v2" /><add key="azure_app_service_staging" value="https://www.myget.org/F/azure-appservice-staging/api/v2" /><add key="azure-appservice-test" value="https://azfunc.pkgs.visualstudio.com/e6a70c92-4128-439f-8012-382fe78d6396/_packaging/azure-appservice-test%40Local/nuget/v3/index.json" /><add key="buildTools" value="https://www.myget.org/F/30de4ee06dd54956a82013fa17a3accb/" /><add key="AspNetVNext" value="https://dotnet.myget.org/F/aspnetcore-dev/api/v3/index.json" /><add key="Microsoft.Azure.Functions.PowerShellWorker" value="https://azfunc.pkgs.visualstudio.com/e6a70c92-4128-439f-8012-382fe78d6396/_packaging/Microsoft.Azure.Functions.PowerShellWorker/nuget/v3/index.json" /></packageSources></configuration>