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

NuGet.Protocol library does not use ConfigureAwait(false) which leads to deadlocks in NuGet plugins #7289

Closed
dtretyakov opened this issue Sep 10, 2018 · 1 comment
Labels
Area:Plugin V2 plugin w/ cross platform support

Comments

@dtretyakov
Copy link

Details about Problem

  • NuGet version: 4.8.x
  • dotnet CLI: 2.1.400+

When using NuGet.Protocol library for communication in NuGet plugins it could cause deadlocks in message processing on the plugin side and as result NuGet tasks fails with "was cancelled" messages like that:

[14:51:36][restore] Starting: C:\TeamCity\buildAgent\tools\NuGet.CommandLine.4.8.0-rtm.5369\tools\NuGet.exe restore C:\TeamCity\buildAgent\work\71412ac3a5525267\NuGetFeedTest.sln -NoCache -Verbosity detailed -Source http://localhost:8080/httpAuth/app/nuget/feed/_Root/default/v3/index.json -Source https://www.nuget.org/api/v2/
[14:51:36][restore] NuGet Version: 4.8.0.5369
[14:51:36][restore] MSBuild auto-detection: using msbuild version '15.6.82.30579' from 'C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\bin'. Use option -MSBuildVersion to force nuget to use a specific version of MSBuild.
...
[14:51:37][restore] Restoring NuGet package NuGetFeedTest.0.0.314-beta.1.
[14:51:37][restore]   GET http://localhost:8080/httpAuth/app/nuget/feed/_Root/default/v3/flatcontainer/nugetfeedtest/0.0.314-beta.1/nugetfeedtest.0.0.314-beta.1.nupkg

[14:51:37][restore] Using C:\TeamCity\buildAgent\plugins\nuget-agent/bin/credential-plugin/net46/CredentialProvider.TeamCity.exe as a credential provider plugin.
[14:51:38][restore]   GET https://www.nuget.org/api/v2/Packages(Id='NuGetFeedTest',Version='0.0.314-beta.1')
[14:51:38][restore]   NotFound https://www.nuget.org/api/v2/Packages(Id='NuGetFeedTest',Version='0.0.314-beta.1') 161ms
[14:51:38][restore]   GET https://www.nuget.org/api/v2/FindPackagesById()?id='NuGetFeedTest'&semVerLevel=2.0.0
[14:51:38][restore]   OK https://www.nuget.org/api/v2/FindPackagesById()?id='NuGetFeedTest'&semVerLevel=2.0.0 137ms
[14:51:42][restore] WARNING: Unable to find version '0.0.314-beta.1' of package 'NuGetFeedTest'.
[14:51:42][restore]   https://www.nuget.org/api/v2/: Package 'NuGetFeedTest.0.0.314-beta.1' is not found on source 'https://www.nuget.org/api/v2/'.
[14:51:42][restore]   http://localhost:8080/httpAuth/app/nuget/feed/_Root/default/v3/index.json: Getting package 'NuGetFeedTest.0.0.314-beta.1' from source 'http://localhost:8080/httpAuth/app/nuget/feed/_Root/default/v3/index.json' was cancelled.
[14:51:42][restore] 
[14:51:43][restore] WARNING: Unable to find version '0.0.314-beta.1' of package 'NuGetFeedTest'.
[14:51:43][restore]   https://www.nuget.org/api/v2/: Package 'NuGetFeedTest.0.0.314-beta.1' is not found on source 'https://www.nuget.org/api/v2/'.
[14:51:43][restore]   http://localhost:8080/httpAuth/app/nuget/feed/_Root/default/v3/index.json: Getting package 'NuGetFeedTest.0.0.314-beta.1' from source 'http://localhost:8080/httpAuth/app/nuget/feed/_Root/default/v3/index.json' was cancelled.
[14:51:43][restore] 
[14:51:43][restore] Errors in packages.config projects
[14:51:43][restore] 
[14:51:43][restore]     Unable to find version '0.0.314-beta.1' of package 'NuGetFeedTest'.
[14:51:43][restore]       https://www.nuget.org/api/v2/: Package 'NuGetFeedTest.0.0.314-beta.1' is not found on source 'https://www.nuget.org/api/v2/'.
[14:51:43][restore] NuGet Config files used:
[14:51:43][restore]     C:\Users\Dmitry.Tretyakov\AppData\Roaming\NuGet\NuGet.Config
[14:51:43][restore]     C:\Program Files (x86)\NuGet\Config\Microsoft.VisualStudio.Offline.config
[14:51:43][restore]       http://localhost:8080/httpAuth/app/nuget/feed/_Root/default/v3/index.json: Getting package 'NuGetFeedTest.0.0.314-beta.1' from source 'http://localhost:8080/httpAuth/app/nuget/feed/_Root/default/v3/index.json' was cancelled.
[14:51:43][restore] 
[14:51:43][restore] Feeds used:
[14:51:43][restore]     http://localhost:8080/httpAuth/app/nuget/feed/_Root/default/v3/index.json
[14:51:43][restore]     https://www.nuget.org/api/v2/
[14:51:43][restore] Process exited with code 1

After adding ConfigureAwait(false) calls within NuGet.Protocol library this use case is unblocked and restore succeeds. Example: dtretyakov/NuGet.Client@e2a50bd

Sample Project

The typical use cause is executing logging during message processing from NuGet:
https://github.com/JetBrains/teamcity-nuget-support/blob/master/nuget-extensions/nuget-plugin/PluginController.cs#L21-L27

Originally was reported in the #6486 (comment)

//cc @jainaashish, @nkolev92, @dtivel

@rrelyea rrelyea added the Area:Plugin V2 plugin w/ cross platform support label Sep 10, 2018
@dtretyakov
Copy link
Author

It looks like using the same approach for logging as in https://github.com/Microsoft/artifacts-credprovider solves the problem with deadlock.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area:Plugin V2 plugin w/ cross platform support
Projects
None yet
Development

No branches or pull requests

2 participants