Skip to content

Commit

Permalink
[0% tested] fix handling of map render/build timeouts
Browse files Browse the repository at this point in the history
  • Loading branch information
PJB3005 committed Jun 3, 2024
1 parent 1e1364f commit 2f5b13f
Showing 1 changed file with 23 additions and 14 deletions.
37 changes: 23 additions & 14 deletions SS14.MapServer/BuildRunners/LocalBuildService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,17 @@ public async Task Build(string directory, CancellationToken cancellationToken =
_log.Information("Started building {ProjectName}", _configuration.MapRendererProjectName);

process.Start();
process.BeginOutputReadLine();
await process.WaitForExitAsync(cancellationToken).WaitAsync(TimeSpan.FromMinutes(_configuration.ProcessTimeoutMinutes), cancellationToken);
process.CancelOutputRead();

if (!process.HasExited)
try
{
process.Kill();
process.BeginOutputReadLine();
await process.WaitForExitAsync(cancellationToken).WaitAsync(TimeSpan.FromMinutes(_configuration.ProcessTimeoutMinutes), cancellationToken);
process.CancelOutputRead();
}
catch (OperationCanceledException)
{
if (!process.HasExited)
process.Kill();
throw new BuildException($"Building timed out {_configuration.MapRendererProjectName}");
}

Expand Down Expand Up @@ -87,20 +91,25 @@ public async Task<string> Run(string directory, string command, List<string> arg

_log.Information("Running: {Command} {Arguments}", command, string.Join(' ', arguments));

await Task.Run(() => process.Start(), cancellationToken).WaitAsync(TimeSpan.FromMinutes(1), cancellationToken);
process.Start();

if (process.HasExited)
throw new BuildException($"Run timed out {_configuration.MapRendererProjectName}");

process.BeginErrorReadLine();
process.BeginOutputReadLine();
await process.WaitForExitAsync(cancellationToken).WaitAsync(TimeSpan.FromMinutes(_configuration.ProcessTimeoutMinutes), cancellationToken);
process.CancelErrorRead();
process.CancelOutputRead();

if (!process.HasExited)
try
{
process.Kill();
process.BeginErrorReadLine();
process.BeginOutputReadLine();
await process.WaitForExitAsync(cancellationToken)
.WaitAsync(TimeSpan.FromMinutes(_configuration.ProcessTimeoutMinutes), cancellationToken);
process.CancelErrorRead();
process.CancelOutputRead();
}
catch (OperationCanceledException)
{
if (!process.HasExited)
process.Kill();

throw new BuildException($"Run timed out {_configuration.MapRendererProjectName}");
}

Expand Down

0 comments on commit 2f5b13f

Please sign in to comment.