Repository navigation
Make Process.Start have a option to change handle inheritance #13943
Description
Activity
I agree we should add this API. IMO we should also make TcpListener have option to change HandleInheritability and change the default behavior to not inherit handles if possible (at least when targeting newer version of the framework).
In most cases we should not change InheritHandles on Process and should rather do it whenever we create handles but we should still have an option to disable this.
I think adding options to TcpListener/TcpClient/Socket would be a good idea. Are there other places where handle inheritance can be a problem? I was not able to create a problem like the one mentioned above by exclusivly opening a file
This seems quite reasonable. As @krwq we should probably do a pass and look into similar classes that perform handle inheritability. This helps in understanding what API we could use.
@pdelvo, We were able to repro this with FileStream although that one creates non-inheritable handles by default so had to override that. I believe that every library should have non-inheritable handles by default but that might be hard to change at this point because of compat reasons
One open question I have is what this would mean when we try to support this feature cross platform. What would it mean to say that handles are not inherited in Unix? Does "handles" here mean open file descriptors? If they are not to be inherited, does the framework have to find and close them in the child process? How does it interact with file descriptors marked FD_CLOEXEC?
I expect there are going to be a fair number of features in System.Diagnostics.Process that result in PlatformNotSupportedException; this might be one of them, if e.g. explicitly closing all fds above 2 doesn't work out or is prohibitive for some reason.
We've reviewed this proposal and don't believe it's ready yet. Please take a look at the notes.
- Reacted by Bhaal22 and Lakshmi Priya Sekar
@Priya91 yeah I could do something, but likely not until after VS 2017 ships (it is an all consuming effort). If @pdelvo wants to start on something, I'd be happy to collaborate as well.
What are the requirements for CoreFx API changes? Does the API need x-plat support, can there be Windows specific elements? Etc.
As a side note, I'd prefer to see a method added to
System.Diagnostics.ProcessStartInfolikepublic void AddInhertiableHandles(IEnumerable<SafeHandle> handles),public void AddInhertiableHandles(IEnumerable<IntPtr> handles)than a misleading property likepublic bool InheritHandles { get; set; }because any time there's a redirection of pipes, inheritance needs to be enabled but consumers of the API do not likely mean to inherit every handle the parent process has.What are the requirements for CoreFx API changes? Does the API need x-plat support
We have the api addition process documented here. It also elaborates on the design principles. Yeah we do need x-plat support, as .NET Core supports Unix platforms as well.
can there be Windows specific elements? Etc.
Are you asking in terms of exposing an API only on Windows? We can't do that, although we have some windows specific APIs in .NET Core and throw PNSE on other platforms.
For now the focus should be more on the API design as you suggested in using a method over property etc, which will take shape once we understand the scenarios and requirements on all platforms.
@Priya91 👍 and thanks.
124 remaining items
(typo in the link @adamsitnik)
Reacted by Adam Sitnik@adamsitnik, it might be worth reaching out to Chad Boles (MSFT employee, or at least was) to have a look at the process class used in the VS Git Integration solution. VS is an extreme scenario with dozens and dozens of child-procs being spun up and down continually. This leads to "handle leakage" problems.
Reacted by Adam Sitnik and Friedrich von Never- addedin-prThere is an active PR which will close this issue when it is mergedThere is an active PR which will close this issue when it is merged
on Mar 30, 2026 - added a commit that references this issue
on Apr 8, 2026 - added a commit that references this issue
on Apr 9, 2026 - locked and limited conversation to collaborators
on May 8, 2026 The API was implemented and released as part of .NET 11 Preview 4. This part of the blog post describes all important aspects of it: https://devblogs.microsoft.com/dotnet/process-api-improvements-in-dotnet-11/#handle-inheritance
- added a commit that references this issue
on Jul 15, 2026
Currently if you call Process.Start internally CreateProcess is called with bInheritHandles = true (hard coded). It would be great to make it possible to change this behavior, e.g. by adding a Property to ProcessStartInfo.
Currently there is no way I know of to change this other then reimplementing System.Diagnostics.Process.
Example
If you run this application twice without exiting the first notepad instance the second instance will not be able to open the tcp port, because notepad is still running. This can be a problem for server applications that are starting child processes themself and crash, or are killed by the user before the socket can be closed.
Design proposal
The easiest way to make this possible is to add a new Property to ProcessStartInfo and use this in the Call to CreateProcess
Questions