fix processex.cs possible problems (#22347)

- `_output ` May be executed in synchronous and asynchronous situations
- Process Is a nullable
This commit is contained in:
Huei Feng 2020-05-30 02:45:48 +08:00 committed by GitHub
parent 78d6ce201f
commit 22c36ad0f0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 7 deletions

View File

@ -197,7 +197,11 @@ namespace Microsoft.AspNetCore.Internal
var exited = Exited.Wait(timeSpan.Value);
if (!exited)
{
_output.WriteLine($"The process didn't exit within the allotted time ({timeSpan.Value.TotalSeconds} seconds).");
lock (_testOutputLock)
{
_output.WriteLine($"The process didn't exit within the allotted time ({timeSpan.Value.TotalSeconds} seconds).");
}
_process.Dispose();
}
else if (assertSuccess && _process.ExitCode != 0)
@ -227,13 +231,16 @@ namespace Microsoft.AspNetCore.Internal
_process.KillTree();
}
_process.CancelOutputRead();
_process.CancelErrorRead();
if (_process != null)
{
_process.CancelOutputRead();
_process.CancelErrorRead();
_process.ErrorDataReceived -= OnErrorData;
_process.OutputDataReceived -= OnOutputData;
_process.Exited -= OnProcessExited;
_process.Dispose();
_process.ErrorDataReceived -= OnErrorData;
_process.OutputDataReceived -= OnOutputData;
_process.Exited -= OnProcessExited;
_process.Dispose();
}
}
}
}