From 3ce5623270f412640fd99dfe91541d3f50a86fa7 Mon Sep 17 00:00:00 2001 From: Josh Studt <32800478+orionstudt@users.noreply.github.com> Date: Fri, 19 Mar 2021 22:16:32 -0400 Subject: [PATCH] [automation/dotnet] - Fix child process stream capture (#6586) --- .../Commands/LocalPulumiCmd.cs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/sdk/dotnet/Pulumi.Automation/Commands/LocalPulumiCmd.cs b/sdk/dotnet/Pulumi.Automation/Commands/LocalPulumiCmd.cs index b9058f64c..9e34cf515 100644 --- a/sdk/dotnet/Pulumi.Automation/Commands/LocalPulumiCmd.cs +++ b/sdk/dotnet/Pulumi.Automation/Commands/LocalPulumiCmd.cs @@ -101,10 +101,22 @@ namespace Pulumi.Automation.Commands proc.Exited += (_, @event) => { - var code = proc.ExitCode; + // this seems odd, since the exit event has been triggered, but + // the exit event being triggered does not mean that the async + // output stream handlers have ran to completion. this method + // doesn't exit until they have, at which point we can be sure + // we have captured the output in its entirety. + // note that if we were to pass an explicit wait time to this + // method it would not wait for the stream handlers. + // see: https://github.com/dotnet/runtime/issues/18789 + proc.WaitForExit(); - var result = new CommandResult(code, standardOutputBuilder.ToString(), standardErrorBuilder.ToString()); - if (code != 0) + var result = new CommandResult( + proc.ExitCode, + standardOutputBuilder.ToString(), + standardErrorBuilder.ToString()); + + if (proc.ExitCode != 0) { var ex = CommandException.CreateFromResult(result); tcs.TrySetException(ex);