提交 d5246bf3 编写于 作者: J Jason Malinowski

Fix race in ProcessRunner.cs where we might not wait for output

It's possible to get Process.OutputDataReceived or ErrorDataReceived
to fire after you've got the Exited message from the process. You must
call WaitForExit to confirm that everything is completely done before
continuing. Otherwise, we return still-mutating lists to the caller
who started the Process which isn't going to be ready for that.
上级 a17513b3
......@@ -129,8 +129,15 @@ public static void OpenFile(string file)
process.Exited += (s, e) =>
{
var processOutput = new ProcessOutput(process.ExitCode, outputLines, errorLines);
taskCompletionSource.TrySetResult(processOutput);
// We must call WaitForExit to make sure we've received all OutputDataReceived/ErrorDataReceived calls
// or else we'll be returning a list we're still modifying. For paranoia, we'll start a task here rather
// than enter right back into the Process type and start a wait which isn't guaranteed to be safe.
Task.Run(() =>
{
process.WaitForExit();
var processOutput = new ProcessOutput(process.ExitCode, outputLines, errorLines);
taskCompletionSource.TrySetResult(processOutput);
});
};
var registration = cancellationToken.Register(() =>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册