Skip to content

Commit 141ef74

Browse files
cgranadeadamsitnik
andauthored
handle processes that don't exit on time more gracefully, fixes #1731. (#1745)
Co-authored-by: Adam Sitnik <[email protected]>
1 parent 4b3d197 commit 141ef74

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

src/BenchmarkDotNet/Running/BenchmarkRunnerClean.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,14 @@ private static (bool success, List<ExecuteResult> executeResults, GcStats gcStat
402402

403403
if (executeResult.ProcessId.HasValue)
404404
{
405-
logger.WriteLineInfo($"// Benchmark Process {executeResult.ProcessId} has exited with code {executeResult.ExitCode}");
405+
if (executeResult.ExitCode is int exitCode)
406+
{
407+
logger.WriteLineInfo($"// Benchmark Process {executeResult.ProcessId} has exited with code {exitCode}.");
408+
}
409+
else
410+
{
411+
logger.WriteLineInfo($"// Benchmark Process {executeResult.ProcessId} failed to exit.");
412+
}
406413
}
407414

408415
executeResults.Add(executeResult);

src/BenchmarkDotNet/Toolchains/DotNetCli/DotNetCliExecutor.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Diagnostics;
33
using System.IO;
4+
using System.Threading;
45
using BenchmarkDotNet.Characteristics;
56
using BenchmarkDotNet.Diagnosers;
67
using BenchmarkDotNet.Engines;
@@ -21,6 +22,7 @@ public class DotNetCliExecutor : IExecutor
2122
public DotNetCliExecutor(string customDotNetCliPath) => CustomDotNetCliPath = customDotNetCliPath;
2223

2324
private string CustomDotNetCliPath { get; }
25+
private static readonly TimeSpan ProcessExitTimeout = TimeSpan.FromSeconds(2);
2426

2527
public ExecuteResult Execute(ExecuteParameters executeParameters)
2628
{
@@ -88,15 +90,15 @@ private ExecuteResult Execute(BenchmarkCase benchmarkCase,
8890

8991
loggerWithDiagnoser.ProcessInput();
9092

91-
if (!process.WaitForExit(milliseconds: 250))
93+
if (!process.WaitForExit(milliseconds: (int)ProcessExitTimeout.TotalMilliseconds))
9294
{
93-
logger.WriteLineInfo("// The benchmarking process did not quit on time, it's going to get force killed now.");
95+
logger.WriteLineInfo($"// The benchmarking process did not quit within {ProcessExitTimeout.TotalSeconds} seconds, it's going to get force killed now.");
9496

9597
consoleExitHandler.KillProcessTree();
9698
}
9799

98-
return new ExecuteResult(true, process.ExitCode, process.Id, loggerWithDiagnoser.LinesWithResults, loggerWithDiagnoser.LinesWithExtraOutput);
100+
return new ExecuteResult(true, process.HasExited ? (int?)process.ExitCode : null, process.Id, loggerWithDiagnoser.LinesWithResults, loggerWithDiagnoser.LinesWithExtraOutput);
99101
}
100102
}
101103
}
102-
}
104+
}

src/BenchmarkDotNet/Toolchains/Results/ExecuteResult.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ namespace BenchmarkDotNet.Toolchains.Results
55
public class ExecuteResult
66
{
77
public bool FoundExecutable { get; }
8-
public int ExitCode { get; }
8+
public int? ExitCode { get; }
99
public int? ProcessId { get; }
1010
public IReadOnlyList<string> Data { get; }
1111
public IReadOnlyList<string> ExtraOutput { get; }
1212

13-
public ExecuteResult(bool foundExecutable, int exitCode, int? processId, IReadOnlyList<string> data, IReadOnlyList<string> linesWithExtraOutput)
13+
public ExecuteResult(bool foundExecutable, int? exitCode, int? processId, IReadOnlyList<string> data, IReadOnlyList<string> linesWithExtraOutput)
1414
{
1515
FoundExecutable = foundExecutable;
1616
Data = data;

0 commit comments

Comments
 (0)