dotnet / dotnet/aspnetcore

Cancel Kestrel write loops on disconnect/reset

Open
#24,836 2 comments 1 reaction 0 assignees View on GitHub
affected-few area-networking enhancement feature-kestrel Perf severity-nice-to-have
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 6h
Merged PRs (30d)
290

Description

https://github.com/dotnet/aspnetcore/blob/4092201629a7feea1ead23202aff4ee8f5b77664/src/Servers/Kestrel/Core/src/Internal/Http2/Http2OutputProducer.cs#L456-L460

https://github.com/dotnet/aspnetcore/blob/a67c217976899db93563353daa6276e438fe677b/src/Servers/Kestrel/Core/src/Internal/Http3/Http3OutputProducer.cs#L372-L376

Kestrel uses a pipe for the response body and a pipe for the connection and runs a copy loop in between. Right now it doesn't check the flushresult and will keep copying even if the client has disconnected or reset the stream.

Proposal: Cancel the ProcessDataWrites loop and complete the response body pipe reader early if the client disconnects or otherwise resets the stream. That will allow application components to check the pipe flush results and also terminate early when the reader is completed.

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.