dotnet / sdk

Core functionality needed to create .NET Core projects, that is shared between Visual Studio and CLI
https://dot.net/core
MIT License
2.71k stars 1.07k forks source link

TaskCancelledException when running `dotnet tool search` #24689

Open jinek opened 2 years ago

jinek commented 2 years ago

Hello! I see cli command dotnet tool search sometimes exits with code 1 and prints exception to error output. I can not reproduce the issue, not sure if may be my system tries to shutdown the process? image

I am sorry, I don't have the stacktrace, I only have part of output left in my custom UI.

Exceptions (if any)

TaskCancelledException SocketException

Further technical details


 Version:   6.0.201
 Commit:    ef40e6aa06

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.19044
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\6.0.201\

Host (useful for support):
  Version: 6.0.3
  Commit:  c24d9a9c91

.NET SDKs installed:
  3.1.417 [C:\Program Files\dotnet\sdk]
  5.0.406 [C:\Program Files\dotnet\sdk]
  6.0.101 [C:\Program Files\dotnet\sdk]
  6.0.201 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 3.1.23 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.15 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 3.1.23 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.15 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 3.1.23 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 5.0.15 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 6.0.1 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 6.0.3 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]```
WeihanLi commented 2 years ago

Think it may relate to a bad network for the NuGet

baronfel commented 2 years ago

We've got a 10-second hard-coded cancellation timespan in the code, and we don't do any special handling of the cancellation exception. We should do better and present the user with a more useful error message if we can't contact nuget in a reasonable time. I think it's also reasonable to expand this 10s timespan - the default HttpClient timeout is 100s, and a DNS query has a maximum duration of 15s, so something longer might be better to allow the DNS resolution to fully fail.

Alternatively - System.CommandLine supports creating and forwarding CancellationTokens that respond to user cancellation, and we should take one of those and flow it down into this call instead. That puts the user in complete control.