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

Tool crashes on url timeout #182

Closed
rvsanten opened this issue Feb 1, 2023 · 9 comments
Closed

Tool crashes on url timeout #182

rvsanten opened this issue Feb 1, 2023 · 9 comments

Comments

@rvsanten
Copy link

rvsanten commented Feb 1, 2023


System.Threading.Tasks.TaskCanceledException: The request was canceled due to the configured HttpClient.Timeout of 10 seconds elapsing.
---> System.TimeoutException: A task was canceled.
---> System.Threading.Tasks.TaskCanceledException: A task was canceled.
at System.Threading.Tasks.TaskCompletionSourceWithCancellation1.WaitWithCancellationAsync(CancellationToken cancellationToken) at System.Net.Http.HttpConnectionPool.GetHttp11ConnectionAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken) at System.Net.Http.HttpConnectionPool.SendWithVersionDetectionAndRetryAsync(HttpRequestMessage request, Boolean async, Boolean doRequestAuth, CancellationToken cancellationToken) at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken) at System.Net.Http.HttpClient.<SendAsync>g__Core|83_0(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationTokenSource cts, Boolean disposeCts, CancellationTokenSource pendingRequestsCts, CancellationToken originalCancellationToken) --- End of inner exception stack trace --- --- End of inner exception stack trace --- at System.Net.Http.HttpClient.HandleFailure(Exception e, Boolean telemetryStarted, HttpResponseMessage response, CancellationTokenSource cts, CancellationToken cancellationToken, CancellationTokenSource pendingRequestsCts) at System.Net.Http.HttpClient.<SendAsync>g__Core|83_0(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationTokenSource cts, Boolean disposeCts, CancellationTokenSource pendingRequestsCts, CancellationToken originalCancellationToken) at NugetUtility.Methods.ExportLicenseTexts(List1 infos) in /home/runner/work/nuget-license/nuget-license/src/Methods.cs:line 1013
at NugetUtility.Program.Execute(PackageOptions options) in /home/runner/work/nuget-license/nuget-license/src/Program.cs:line 71


See line:

public async Task ExportLicenseTexts(List<LibraryInfo> infos)

I am using your tool for quite some time now, works great and helps me a lot! But now I ran into a problem that when there is a download timeout (export licenses) the application crashes. It would be nice when the execption is caught and logged. Now our build fails for difficult to troubleshoot error.

try..catch for the ExportLicenseTexts function ->
catch (TimeOutException ex)
{
WriteOutput($"Problem during download of License url: {fileToDownload} -> {ex.Message}");
}

@tomchavakis
Copy link
Owner

Hi @rvsanten,

Thank you for reporting this important issue.
I'll try to resolve the issue asap and keep you posted.

@dbeusink
Copy link

dbeusink commented Feb 9, 2023

Can confirm having this issue as well. Thanks for working on this issue @tomchavakis . Will follow this issue. Please let me know if I can test something for you.

@tomchavakis
Copy link
Owner

tomchavakis commented Feb 15, 2023

Hi @dbeusink, @rvsanten
Thank you for your message. Can you please run a test to see if the issue has been resolved with the PR code?
branch: ftr-tmp-canc

Thank you in advance

@dbeusink
Copy link

Hi @tomchavakis , thank you for your fast resolution. I'm sorry for my late response. The fix works well but the HTTP client will sometimes throw an OperationCanceledException as well. I've added a suggestion to PR #184.

I also noticed that GetLicenceFromNpkgFile is also using the HTTP client to make a request without a try/catch. Perhaps we could also apply the same fix to this method to catch a possible timeout exception and log the error.
Inside the same method are some other try/catch clauses for file operations. When an Exception is thrown nothing is logged and the file will be skipped. Perhaps we can also add some logging here? I tried for example to block licenses.nuget.org and the software just silently continued without copying the files.

Thank you for your fast support and I will try to help you out faster next time.

Thanks!

@tomchavakis
Copy link
Owner

HI @dbeusink ,
Thank you for your suggestion. Maybe I will ask you to run one more test before merging to master.

@tomchavakis
Copy link
Owner

@dbeusink, Can you pull the new code and run a test please to confirm that the update is fine?
Thank you

@dbeusink
Copy link

dbeusink commented Feb 23, 2023

Can confirm it's working as expected; both exception types are handled and logged.
Log output:

Attempting to download: https://www.nuget.org/api/v2/package/coverlet.collector/3.2.0
Attempting to download https://licenses.nuget.org/MIT to C:\Temp\LicenseOut\coverlet.collector_3.2.0.txt
TaskCanceledException during download of license url https://licenses.nuget.org/MIT exception The operation was canceled.
Attempting to download: https://www.nuget.org/api/v2/package/coverlet.collector/3.2.0
Attempting to download https://licenses.nuget.org/MIT to C:\Temp\LicenseOut\coverlet.collector_3.2.0.txt
TaskCanceledException during download of license url https://licenses.nuget.org/MIT exception The operation was canceled.
Attempting to download: https://www.nuget.org/api/v2/package/fluentassertions/6.9.0
Attempting to download https://licenses.nuget.org/Apache-2.0 to C:\Temp\LicenseOut\FluentAssertions_6.9.0.txt
TaskCanceledException during download of license url https://licenses.nuget.org/Apache-2.0 exception The operation was canceled.
Attempting to download: https://www.nuget.org/api/v2/package/fluentassertions/6.9.0
Attempting to download https://licenses.nuget.org/Apache-2.0 to C:\Temp\LicenseOut\FluentAssertions_6.9.0.txt
TaskCanceledException during download of license url https://licenses.nuget.org/Apache-2.0 exception The operation was canceled.
Attempting to download: https://www.nuget.org/api/v2/package/microsoft.csharp/4.7.0
Attempting to download https://licenses.nuget.org/MIT to C:\Temp\LicenseOut\Microsoft.CSharp_4.7.0.txt
TaskCanceledException during download of license url https://licenses.nuget.org/MIT exception The operation was canceled.
Attempting to download: https://www.nuget.org/api/v2/package/microsoft.csharp/4.7.0
Attempting to download https://licenses.nuget.org/MIT to C:\Temp\LicenseOut\Microsoft.CSharp_4.7.0.txt
TaskCanceledException during download of license url https://licenses.nuget.org/MIT exception The operation was canceled.
Attempting to download: https://www.nuget.org/api/v2/package/microsoft.net.test.sdk/17.4.1
Attempting to download: https://www.nuget.org/api/v2/package/microsoft.tpl.dataflow/4.5.24
Attempting to download http://go.microsoft.com/fwlink/?LinkId=329770 to C:\Temp\LicenseOut\Microsoft.Tpl.Dataflow_4.5.24.txt
TaskCanceledException during download of license url http://go.microsoft.com/fwlink/?LinkId=329770 exception The operation was canceled.
Attempting to download https://raw.githubusercontent.com/moq/moq4/main/License.txt to C:\Temp\LicenseOut\Moq_4.18.4.txt
OperationCanceledException during download of license url https://raw.githubusercontent.com/moq/moq4/main/License.txt exception The operation was canceled.
Attempting to download: https://www.nuget.org/api/v2/package/xunit/2.4.2
Attempting to download https://licenses.nuget.org/Apache-2.0 to C:\Temp\LicenseOut\xunit_2.4.2.txt
TaskCanceledException during download of license url https://licenses.nuget.org/Apache-2.0 exception The operation was canceled.
Attempting to download: https://www.nuget.org/api/v2/package/xunit/2.4.2
Attempting to download https://licenses.nuget.org/Apache-2.0 to C:\Temp\LicenseOut\xunit_2.4.2.txt
TaskCanceledException during download of license url https://licenses.nuget.org/Apache-2.0 exception The operation was canceled.
Attempting to download: https://www.nuget.org/api/v2/package/xunit.runner.visualstudio/2.4.5```

@tomchavakis
Copy link
Owner

Thank you @dbeusink ,

I will release a new version in order to take advantage of the fix.

Thank you for your support.

@rvsanten
Copy link
Author

Thank you for solving this so quickly, will integrate the new version somewhere next week. And @dbeusink thank you for testing and confirming!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants