Use Process.StartAndForget for fire-and-forget process launches#54093
Draft
Use Process.StartAndForget for fire-and-forget process launches#54093
Conversation
… process launching Agent-Logs-Url: https://github.com/dotnet/sdk/sessions/530c5ee1-aa5c-4ad3-ba82-fe8274732a35 Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
Copilot created this pull request from a session on behalf of
adamsitnik
April 27, 2026 12:06
View session
adamsitnik
reviewed
Apr 27, 2026
| ]), | ||
| UseShellExecute = false, | ||
| RedirectStandardInput = true, | ||
| RedirectStandardOutput = true, |
Member
There was a problem hiding this comment.
to other reviewers: the idea of using Process.StartAndForget is to avoid resource leaks, but in this case redirecting standard out/err and NOT consuming them can simply lead to deadlocks: the started process can fill the pipe buffer and will just wait for the data to be consumed on some Console.Write* method. And here nothing was consuming the produced data.
If it was done to prevent from printing the produced output to terminal then the new method takes care of that as well, as it by default redirects to NUL device (unless configured explicitly)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adopt
Process.StartAndForget(dotnet/runtime#126078) at call sites whereProcess.Startwas used in a fire-and-forget pattern, leaking the returnedProcesshandle.CleanFileBasedAppArtifactsCommand.cs— cleanup subprocess launched with discarded return valueServerConnection.cs— Razor server subprocess launched, only.Idread from the handleBoth sites set
RedirectStandardInput/Output/Errorbut never consumed the streams; these flags are removed sinceStartAndForgetredirects to the null device by default and rejects explicit redirect flags.