Skip to content

Commit

Permalink
Fixes a nasty Process.WaitForExit() race condition (#125)
Browse files Browse the repository at this point in the history
  • Loading branch information
daveaglick committed Feb 13, 2020
1 parent c79a8d0 commit 7723232
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions ReleaseNotes.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# 2.5.1

- [Fix] Removed the explicit encoding parameter when generating a `SourceText` in Buildalyzer.Workspaces (#128)
- [Fix] Fixes a race condition in `ProcessRunner` in `Process.WaitForExit()` calls (#125, thanks @duncanawoods)

# 2.5.0

Expand Down
13 changes: 12 additions & 1 deletion src/Buildalyzer/Environment/ProcessRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,18 @@ private void ProcessExited(object sender, EventArgs e)

public void WaitForExit() => Process.WaitForExit();

public bool WaitForExit(int timeout) => Process.WaitForExit(timeout);
public bool WaitForExit(int timeout)
{
bool exited = Process.WaitForExit(timeout);
if (exited)
{
// To ensure that asynchronous event handling has been completed, call the WaitForExit() overload that takes no parameter after receiving a true from this overload.
// From https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.process.waitforexit?redirectedfrom=MSDN&view=netcore-3.1#System_Diagnostics_Process_WaitForExit_System_Int32_
// See also https://github.com/dotnet/runtime/issues/27128
Process.WaitForExit();
}
return exited;
}

public void Dispose()
{
Expand Down

0 comments on commit 7723232

Please sign in to comment.