Skip to content

Resource leak in TcpChannel when opening and closing TCP Proxies. #90

Closed

Description

@scottcnevin

In TcpChannel we found that opening and closing TCP Proxies between client and server would leak resources
on the Gen2 heap that were never reclaimed. We have an application that grew to a run-time foot-print of 5 Gb! Running Redgate ANTS memory profiler found a set of objects that were being retained in Gen2 due to a number of references related to the SocketAsyncEventArgs. In the changes, each step in this was able to finally get a flat memory profile when making and breaking connections between client and server.

authlogics#1

Activity

  1. tylerje commented on Apr 4, 2024

    @tylerje
    Member

    Love it. Submit the PR and I'll run some tests locally and if everything checks out, I'll get a new version of the package out asap.

  2. scottcnevin commented on Apr 8, 2024

    @scottcnevin
    Author

    Tyler -- not really sure what to do at this point. I opened the PR and made the changes. Not sure how to "submit" the PR at this point on github.

    authlogics#1

  3. tylerje commented on Apr 8, 2024

    @tylerje
    Member

    @scottcnevin the PR you created and referenced is into your own fork. As such, I cannot approve that PR nor would it land in the origin in my repo. See the doc:
    https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request-from-a-fork

  4. tylerje commented on Aug 18, 2026

    @tylerje
    Member

    Resolved for 6.0.1. TcpChannel connection setup now detaches the SocketAsyncEventArgs.Completed handler, clears socket/endpoint references, and disposes the event arguments in a finally block. The client socket is also disposed when connection setup throws. This breaks the retained completion/resource graph described in the report. Added a targeted test that verifies the connection event resources take the cleanup path on both supported test targets.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      ⌂ 换网址