dotnet / dotnet/aspnetcore

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

Open
#13,292 7 comments 0 reactions 0 assignees View on GitHub
affected-very-few area-networking bug severity-nice-to-have
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 6h
Merged PRs (30d)
290

Description

### 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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.