Skip to content

[Breaking change]: Changed AnonymousPipeServerStream.Dispose behaviour for HandleInheritability.Inheritable #32713

Closed

Description

@adamsitnik

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

  • Binary incompatible: Existing binaries may encounter a breaking change in behavior, such as failure to load/execute or different run-time behavior.
  • Source incompatible: Source code may encounter a breaking change in behavior when targeting the new runtime/component/SDK, such as compile errors or different run-time behavior.

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

Activity

  1. added
    breaking-change
    on Nov 23, 2022
  2. added
    ⌚ Not Triaged
    source incompatible
    on Nov 23, 2022
  3. added
    🗺️ reQUEST
    on Dec 1, 2022
  4. added
    📌 seQUESTered
    and removed
    🗺️ reQUEST
    on Dec 1, 2022
  5. added
    🏁 Release: .NET 8
    on Dec 3, 2022
  6. added
    🗺️ reQUEST
    and removed
    🗺️ reQUEST
    on Jan 4, 2023
  7. ghost added
    in-pr
    on Jan 30, 2023
  8. moved this from 🔖 Ready to 🏗 In progress in dotnet/docs January 2023 sprinton Jan 30, 2023
  9. moved this from 🏗 In progress to ✅ Done in dotnet/docs January 2023 sprinton Jan 31, 2023
  10. ghost removed
    in-pr
    on Jan 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

🏁 Release: .NET 8📌 seQUESTeredbreaking-changesource incompatible

Type

No type

Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions