Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[0% tested] fix handling of map render/build timeouts #21

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading