Skip to content

When using a ConnectionHandler, socket is left open after Kestrel close #13292

Open
@mconnew

Description

@mconnew

Describe the bug

AspNetCore 2.1 doesn't automatically close the socket when a ConnectionHandler's OnConnectedAsync returned Task completes. On AspNetCore 2.2, the socket is automatically closed on Task completion. If the connection handler implementation never closes the socket, then the socket remains open indefinitely, even after Dispose has been called on the IWebHost.

To Reproduce

Steps to reproduce the behavior:

  1. Using this version of ASP.NET Core '2.1'
  2. Create a connection handler which returns a completed Task. Start the webhost and create a connection to the configured port. Dispose the webhost. Clients socket remains connected and is able to call send and receive on the socket (which don't complete as there's nothing reading or writing on the server side of the socket).

Expected behavior

When calling Dispose on the webhost, all sockets will get disconnected.

Additional context

I discovered this when developing CoreWCF. If you need a repro, I can make a custom branch where our unit tests fail demonstrating this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    affected-very-fewThis issue impacts very few customersarea-networkingIncludes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractionsbugThis issue describes a behavior which is not expected - a bug.severity-nice-to-haveThis label is used by an internal tool

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions