Skip to content

Commit f7fa98c

Browse files
committed
C#: Remove the timeout bool logic in the feed manager.
1 parent 945cf0b commit f7fa98c

1 file changed

Lines changed: 13 additions & 39 deletions

File tree

  • csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching

csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/FeedManager.cs

Lines changed: 13 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,12 @@ internal sealed partial class FeedManager : IDisposable
6060
/// </summary>
6161
public ImmutableHashSet<string> InheritedFeeds => AllFeeds.Except(ExplicitFeeds).ToImmutableHashSet();
6262

63-
private readonly Lazy<(bool, ImmutableHashSet<string>)> lazyReachableExplicitFeeds;
64-
65-
/// <summary>
66-
/// Gets whether there was a timeout when checking the reachability of the explicitly configured NuGet feeds.
67-
/// </summary>
68-
public bool ExplicitFeedTimeout => lazyReachableExplicitFeeds.Value.Item1;
63+
private readonly Lazy<ImmutableHashSet<string>> lazyReachableExplicitFeeds;
6964

7065
/// <summary>
7166
/// Gets the list of reachable NuGet feeds that are explicitly configured.
7267
/// </summary>
73-
public ImmutableHashSet<string> ReachableExplicitFeeds => lazyReachableExplicitFeeds.Value.Item2;
68+
public ImmutableHashSet<string> ReachableExplicitFeeds => lazyReachableExplicitFeeds.Value;
7469

7570
private readonly Lazy<ImmutableHashSet<string>> lazyReachableFeeds;
7671
/// <summary>
@@ -96,15 +91,11 @@ public FeedManager(ILogger logger, IDotNet dotnet, DependabotProxy? dependabotPr
9691

9792
lazyExplicitFeeds = new Lazy<ImmutableHashSet<string>>(GetExplicitFeeds);
9893
lazyAllFeeds = new Lazy<ImmutableHashSet<string>>(GetAllFeeds);
99-
lazyReachableExplicitFeeds = new Lazy<(bool, ImmutableHashSet<string>)>(() =>
100-
{
101-
var timeout = CheckSpecifiedFeeds(ExplicitFeeds, out var reachableFeeds);
102-
return (timeout, reachableFeeds);
103-
});
94+
lazyReachableExplicitFeeds = new Lazy<ImmutableHashSet<string>>(() => CheckSpecifiedFeeds(ExplicitFeeds));
10495
lazyReachableFeeds = new Lazy<ImmutableHashSet<string>>(() =>
10596
{
10697
// Inherited feeds should only be used, if they are indeed reachable (as they may be environment specific).
107-
CheckSpecifiedFeeds(InheritedFeeds, out var reachableInheritedFeeds);
98+
var reachableInheritedFeeds = CheckSpecifiedFeeds(InheritedFeeds);
10899
return ReachableExplicitFeeds.Union(reachableInheritedFeeds).ToImmutableHashSet();
109100
});
110101
lazyReachableFallbackFeeds = new Lazy<ImmutableHashSet<string>>(() =>
@@ -271,7 +262,7 @@ private static async Task<HttpResponseMessage> ExecuteGetRequest(string address,
271262
return await httpClient.GetAsync(address, HttpCompletionOption.ResponseHeadersRead, cancellationToken);
272263
}
273264

274-
private bool IsFeedReachable(string feed, int timeoutMilliSeconds, int tryCount, out bool isTimeout)
265+
private bool IsFeedReachable(string feed, int timeoutMilliSeconds, int tryCount)
275266
{
276267
logger.LogInfo($"Checking if NuGet feed '{feed}' is reachable...");
277268

@@ -304,8 +295,6 @@ private bool IsFeedReachable(string feed, int timeoutMilliSeconds, int tryCount,
304295

305296
using HttpClient client = new(httpClientHandler);
306297

307-
isTimeout = false;
308-
309298
for (var i = 0; i < tryCount; i++)
310299
{
311300
using var cts = new CancellationTokenSource();
@@ -335,7 +324,6 @@ private bool IsFeedReachable(string feed, int timeoutMilliSeconds, int tryCount,
335324
}
336325

337326
logger.LogWarning($"Didn't receive answer from NuGet feed '{feed}'. Tried it {tryCount} times.");
338-
isTimeout = true;
339327
return false;
340328
}
341329

@@ -359,12 +347,8 @@ private HashSet<string> GetExcludedFeeds()
359347
/// Checks that we can connect to the specified NuGet feeds.
360348
/// </summary>
361349
/// <param name="feeds">The set of package feeds to check.</param>
362-
/// <param name="reachableFeeds">The list of feeds that were reachable.</param>
363-
/// <returns>
364-
/// True if there is a timeout when trying to reach the feeds (excluding any feeds that are configured
365-
/// to be excluded from the check) or false otherwise.
366-
/// </returns>
367-
private bool CheckSpecifiedFeeds(ImmutableHashSet<string> feeds, out ImmutableHashSet<string> reachableFeeds)
350+
/// <returns>The list of feeds that were reachable.</returns>
351+
private ImmutableHashSet<string> CheckSpecifiedFeeds(ImmutableHashSet<string> feeds)
368352
{
369353
// Exclude any feeds from the feed check that are configured by the corresponding environment variable.
370354
// These feeds are always assumed to be reachable.
@@ -380,12 +364,10 @@ private bool CheckSpecifiedFeeds(ImmutableHashSet<string> feeds, out ImmutableHa
380364
return true;
381365
}).ToHashSet();
382366

383-
var reachable = GetReachableNuGetFeeds(feedsToCheck, isFallback: false, out var isTimeout);
367+
var reachable = GetReachableNuGetFeeds(feedsToCheck, isFallback: false);
384368

385369
// Always consider feeds excluded for the reachability check as reachable.
386-
reachableFeeds = reachable.Union(feeds.Where(feed => excludedFeeds.Contains(feed))).ToImmutableHashSet();
387-
388-
return isTimeout;
370+
return reachable.Union(feeds.Where(feed => excludedFeeds.Contains(feed))).ToImmutableHashSet();
389371
}
390372

391373
/// <summary>
@@ -398,7 +380,7 @@ public bool IsDefaultFeedReachable()
398380
if (CheckNugetFeedResponsiveness)
399381
{
400382
var (initialTimeout, tryCount) = GetFeedRequestSettings(isFallback: false);
401-
return IsFeedReachable(PublicNugetOrgFeed, initialTimeout, tryCount, out var _);
383+
return IsFeedReachable(PublicNugetOrgFeed, initialTimeout, tryCount);
402384
}
403385

404386
return true;
@@ -409,22 +391,15 @@ public bool IsDefaultFeedReachable()
409391
/// </summary>
410392
/// <param name="feedsToCheck">The feeds to check.</param>
411393
/// <param name="isFallback">Whether the feeds are fallback feeds or not.</param>
412-
/// <param name="isTimeout">Whether a timeout occurred while checking the feeds.</param>
413394
/// <returns>The list of feeds that could be reached.</returns>
414-
private List<string> GetReachableNuGetFeeds(HashSet<string> feedsToCheck, bool isFallback, out bool isTimeout)
395+
private List<string> GetReachableNuGetFeeds(HashSet<string> feedsToCheck, bool isFallback)
415396
{
416397
var fallbackStr = isFallback ? "fallback " : "";
417398
logger.LogInfo($"Checking {fallbackStr}NuGet feed reachability on feeds: {string.Join(", ", feedsToCheck.OrderBy(f => f))}");
418399

419400
var (initialTimeout, tryCount) = GetFeedRequestSettings(isFallback);
420-
var timeout = false;
421401
var reachableFeeds = feedsToCheck
422-
.Where(feed =>
423-
{
424-
var reachable = IsFeedReachable(feed, initialTimeout, tryCount, out var feedTimeout);
425-
timeout |= feedTimeout;
426-
return reachable;
427-
})
402+
.Where(feed => IsFeedReachable(feed, initialTimeout, tryCount))
428403
.ToList();
429404

430405
if (reachableFeeds.Count == 0)
@@ -436,7 +411,6 @@ private List<string> GetReachableNuGetFeeds(HashSet<string> feedsToCheck, bool i
436411
logger.LogInfo($"Reachable {fallbackStr}NuGet feeds: {string.Join(", ", reachableFeeds.OrderBy(f => f))}");
437412
}
438413

439-
isTimeout = timeout;
440414
return reachableFeeds;
441415
}
442416

@@ -460,7 +434,7 @@ private List<string> GetReachableFallbackNugetFeeds()
460434
}
461435
}
462436

463-
return GetReachableNuGetFeeds(fallbackFeeds, isFallback: true, out var _);
437+
return GetReachableNuGetFeeds(fallbackFeeds, isFallback: true);
464438
}
465439

466440
private ImmutableHashSet<string> GetExplicitFeeds()

0 commit comments

Comments
 (0)