Description
The DisposeLocalCopyOfClientHandle method should be called after the client handle has been passed to the child process. Not doing so can cause resource leaks similar to this one.
To lower the chances for introducing similar bugs for users who don't call DisposeLocalCopyOfClientHandle, the behaviour of AnonymousPipeServerStream.Dispose has been improved.
Version
.NET 8 Preview 1
Previous behavior
The client handle owned by the AnonymousPipeServerStream instance was not being disposed by AnonymousPipeServerStream.Dispose unless the handle was not exposed at all.
New behavior
The client handle owned by the server created for out-of-proc communication (HandleInheritability.Inheritable passed to AnonymousPipeServerStream ctor) is going to get disposed by AnonymousPipeServerStream.Dispose as long as it's not exposed by using the ClientSafePipeHandle property.
Type of breaking change
Reason for change
Avoiding a common resource leak.
Recommended action
Do not reuse client handle exposed as a string via GetClientHandleAsString method by the server created for out-of-proc communication (HandleInheritability.Inheritable passed to AnonymousPipeServerStream ctor) after the server instance has been Disposed.
// THIS IS VERY BAD IDEA, DON'T DO IT!
AnonymousPipeServerStream server = new (PipeDirection.Out, HandleInheritability.Inheritable);
SafePipeHandle clientPipeHandle = new (nint.Parse(server.GetClientHandleAsString()), ownsHandle: true);
server.Dispose();
// clientPipeHandle is now CLOSED
Feature area
Core .NET libraries
Affected APIs
AnonymousPipeServerStream.Dispose
Associated WorkItem - 45474
Description
The DisposeLocalCopyOfClientHandle method should be called after the client handle has been passed to the child process. Not doing so can cause resource leaks similar to this one.
To lower the chances for introducing similar bugs for users who don't call
DisposeLocalCopyOfClientHandle, the behaviour ofAnonymousPipeServerStream.Disposehas been improved.Version
.NET 8 Preview 1
Previous behavior
The client handle owned by the
AnonymousPipeServerStreaminstance was not being disposed byAnonymousPipeServerStream.Disposeunless the handle was not exposed at all.New behavior
The client handle owned by the server created for out-of-proc communication (
HandleInheritability.Inheritablepassed toAnonymousPipeServerStreamctor) is going to get disposed byAnonymousPipeServerStream.Disposeas long as it's not exposed by using the ClientSafePipeHandle property.Type of breaking change
Reason for change
Avoiding a common resource leak.
Recommended action
Do not reuse client handle exposed as a
stringvia GetClientHandleAsString method by the server created for out-of-proc communication (HandleInheritability.Inheritablepassed toAnonymousPipeServerStreamctor) after the server instance has beenDisposed.Feature area
Core .NET libraries
Affected APIs
AnonymousPipeServerStream.DisposeAssociated WorkItem - 45474