Skip to content

Commit a5f3ccf

Browse files
committed
C#: Allow only three dotnet --info retry attempts.
1 parent af64e33 commit a5f3ccf

File tree

1 file changed

+16
-10
lines changed
  • csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching

1 file changed

+16
-10
lines changed

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

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Collections.ObjectModel;
44
using System.IO;
55
using System.Linq;
6+
using System.Threading;
67
using Newtonsoft.Json.Linq;
78

89
using Semmle.Util;
@@ -38,18 +39,23 @@ private DotNet(ILogger logger, string? dotNetPath, TemporaryDirectory tempWorkin
3839

3940
private void Info()
4041
{
41-
var exitCode = dotnetCliInvoker.RunCommandExitCode("--info", silent: false);
42-
switch (exitCode)
42+
// Allow up to three retry attempts to run `dotnet --info`, to mitigate transient issues
43+
for (int attempt = 0; attempt < 4; attempt++)
4344
{
44-
case 0:
45-
break;
46-
case 143:
47-
logger.LogWarning("Running 'dotnet --info' failed with exit code 143.");
48-
break;
49-
default:
50-
throw new Exception($"{dotnetCliInvoker.Exec} --info failed with exit code {exitCode}.");
45+
var exitCode = dotnetCliInvoker.RunCommandExitCode("--info", silent: false);
46+
switch (exitCode)
47+
{
48+
case 0:
49+
return;
50+
case 143 when attempt < 3:
51+
logger.LogWarning($"Running 'dotnet --info' failed with exit code 143 on attempt {attempt}, retrying...");
52+
var sleep = Math.Pow(2, attempt) * 1000;
53+
Thread.Sleep((int)sleep);
54+
break;
55+
default:
56+
throw new Exception($"{dotnetCliInvoker.Exec} --info failed with exit code {exitCode}.");
57+
}
5158
}
52-
5359
}
5460

5561
private string GetRestoreArgs(RestoreSettings restoreSettings)

0 commit comments

Comments
 (0)