Skip to content

Commit

Permalink
Prevent IsNuGetPublished from deadlocking if source fails to fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
germane_rmd committed Aug 17, 2023
1 parent 09e3aa7 commit 42e51aa
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions source/Cake.ExtendedNuGet/ExtendedNuGetAliases.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
using NuGet.Protocol.Core.Types;
using NuGet.Versioning;

using LogLevel = Cake.Core.Diagnostics.LogLevel;
using Verbosity = Cake.Core.Diagnostics.Verbosity;

namespace Cake.ExtendedNuGet
{
/// <summary>
Expand Down Expand Up @@ -112,18 +115,21 @@ public static bool IsNuGetPublished(this ICakeContext context, string packageId,

Task.Run(async () =>
{
var nuSource = Repository.Factory.GetCoreV3(nugetSource);
using var nuCache = new SourceCacheContext();
var nuLogger = NullLogger.Instance;
var pkgRes = await nuSource.GetResourceAsync<FindPackageByIdResource>();
try
{
var nuSource = Repository.Factory.GetCoreV3(nugetSource);
using var nuCache = new SourceCacheContext();
var nuLogger = NullLogger.Instance;
var pkgRes = await nuSource.GetResourceAsync<FindPackageByIdResource>();
var pkgInfo = await pkgRes.GetDependencyInfoAsync(packageId, new NuGetVersion(version.ToString()), nuCache, nuLogger, default);
tcsPublished.TrySetResult(pkgInfo?.PackageIdentity?.Id?.Equals(packageId, StringComparison.OrdinalIgnoreCase) ?? false);
}
catch
catch(Exception ex)
{
context.Log.Write(Verbosity.Diagnostic, LogLevel.Error,
$"Failed to read nuget source repository information: {ex.Message}");
tcsPublished.TrySetResult(false);
}
});
Expand Down

0 comments on commit 42e51aa

Please sign in to comment.