Browse Source

DockerRunner: include stderr in log on failure. (#1059)

philliphoff-arm64
Tom Deseyn 5 years ago
committed by GitHub
parent
commit
b1aaca8c5d
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 21
      src/Microsoft.Tye.Core/ProcessUtil.cs
  2. 5
      src/Microsoft.Tye.Hosting/DockerRunner.cs

21
src/Microsoft.Tye.Core/ProcessUtil.cs

@ -114,9 +114,12 @@ namespace Microsoft.Tye
process.Exited += (_, e) =>
{
// Even though the Exited event has been raised, WaitForExit() must still be called to ensure the output buffers
// have been flushed before the process is considered completely done.
process.WaitForExit();
lock (process)
{
// Even though the Exited event has been raised, WaitForExit() must still be called to ensure the output buffers
// have been flushed before the process is considered completely done.
process.WaitForExit();
}
if (throwOnError && process.ExitCode != 0)
{
@ -128,11 +131,15 @@ namespace Microsoft.Tye
}
};
process.Start();
onStart?.Invoke(process.Id);
// lock ensures we're reading output when WaitForExit is called in process.Exited event.
lock (process)
{
process.Start();
onStart?.Invoke(process.Id);
process.BeginOutputReadLine();
process.BeginErrorReadLine();
process.BeginOutputReadLine();
process.BeginErrorReadLine();
}
var cancelledTcs = new TaskCompletionSource<object?>();
await using var _ = cancellationToken.Register(() => cancelledTcs.TrySetResult(null));

5
src/Microsoft.Tye.Hosting/DockerRunner.cs

@ -311,16 +311,17 @@ namespace Microsoft.Tye.Hosting
status.DockerNetwork = dockerNetwork;
WriteReplicaToStore(replica);
var stderr = new StringBuilder();
var result = await application.ContainerEngine.RunAsync(
command,
throwOnError: false,
cancellationToken: cancellationToken,
outputDataReceived: data => service.Logs.OnNext($"[{replica}]: {data}"),
errorDataReceived: data => service.Logs.OnNext($"[{replica}]: {data}"));
errorDataReceived: data => { service.Logs.OnNext($"[{replica}]: {data}"); stderr.AppendLine(data); });
if (result.ExitCode != 0)
{
_logger.LogError("docker run failed for {ServiceName} with exit code {ExitCode}:" + result.StandardError, service.Description.Name, result.ExitCode);
_logger.LogError("docker run failed for {ServiceName} with exit code {ExitCode}: " + stderr, service.Description.Name, result.ExitCode);
service.Replicas.TryRemove(replica, out var _);
service.ReplicaEvents.OnNext(new ReplicaEvent(ReplicaState.Removed, status));

Loading…
Cancel
Save