-
Notifications
You must be signed in to change notification settings - Fork 172
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ProcessRunner: do not call WaitForExit until redirection has started #2000
Conversation
This bug has personally been affecting my builds that run against .NET 6. Assuming this fix is accepted, is there any chance it can be back-ported to that SDK? |
@AArnott this seems fine to me but you might know of an easier way? |
I don't usually redirect using the Begin methods. I just use the streams directly, and I don't assume that the streams are fully read by the time the process exits -- the readers will read till the streams hit EOF, and I've written code at times to block my process-exited processing until those EOFs are hit, rather than blocking the A couple nits though:
|
The only
I agree - this code can probably be refactored as to not rely on undocumented behavior of |
It could though, if you add a PackageReference to it. :) The dependency isn't VS-specific.
Thread pool threads aren't free. But as you're in a special purpose process, how you spend them is up to you. In VS, we find that blocking threadpool threads cause ui delays a lot. |
Sorry, I'm not sure what you're suggesting for this PR then. I think the options here are
I don't see the point in doing option 2 since we incur the cost of a thread pool thread and the overhead of async/await. I am fine changing this PR to use option 3, but like I said I was trying to minimize code changes 😃 |
I don't think any change is required. |
dotnet-format has to be source buildable because it ships in the SDK. I would suspect VS.Threading likely isn't source buildable. |
Certainly not by the definition that you're using. |
@sharwell are there any changes you would want on this PR? @AArnott mentioned above that they do not think any changes are required. There mentioned, there are better ways to do this that would require refactoring a lot of how this works, but since there are no tests for these methods I did not want to introduce too many changes. |
If
Process.WaitForExit
is called beforeBeginOutputReadLine
and/orBeginErrorReadLine
is called,WaitForExit
will not wait until the end of their streams are redirected. This results in a race condition where, if too much time elapses betweenProcess.Start
andBeginOutputReadLine
/BeginErrorReadLine
, it's possible to not receive any output before the process exits and theTaskCompletionSource
gets its result.This is particularly problematic since slower build machines that use this tool may randomly see the tool failing due to it not finding the dotnet CLI version, since the version is read from a
dotnet --version
process output redirection.