Skip to content

Use Process.StartAndForget for fire-and-forget process launches#54093

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/update-process-start-usage
Draft

Use Process.StartAndForget for fire-and-forget process launches#54093
Copilot wants to merge 2 commits intomainfrom
copilot/update-process-start-usage

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 27, 2026

Adopt Process.StartAndForget (dotnet/runtime#126078) at call sites where Process.Start was used in a fire-and-forget pattern, leaking the returned Process handle.

  • CleanFileBasedAppArtifactsCommand.cs — cleanup subprocess launched with discarded return value
  • ServerConnection.cs — Razor server subprocess launched, only .Id read from the handle

Both sites set RedirectStandardInput/Output/Error but never consumed the streams; these flags are removed since StartAndForget redirects to the null device by default and rejects explicit redirect flags.

- Process.Start(startInfo);
+ _ = Process.StartAndForget(startInfo);
- var process = Process.Start(startInfo);
- processId = process.Id;
+ processId = Process.StartAndForget(startInfo);

Note: Will not compile until MicrosoftNETCoreAppRefPackageVersion is updated to a build containing Process.StartAndForget.

… 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>
]),
UseShellExecute = false,
RedirectStandardInput = true,
RedirectStandardOutput = true,
Copy link
Copy Markdown
Member

@adamsitnik adamsitnik Apr 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants