dotnet / dotnet/aspnetcore

Leaking tasks when aborting HTTP/2 Connections

Open
#51,307 2 comments 0 reactions 0 assignees View on GitHub
area-networking HTTP2
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 6h
Merged PRs (30d)
290

Description

### Is there an existing issue for this?

- [X] I have searched the existing issues

### Describe the bug

When lots of connections are aborted very quickly, a few of them get stuck in [this loop](https://github.com/dotnet/aspnetcore/blob/9719821d5bb09c7cf75f82a223e8b210da65aaca/src/Servers/Kestrel/Core/src/Internal/Http2/Http2Connection.cs#L396) waiting on tasks that never terminate. The remaining (unscheduled) tasks are
```
Microsoft.AspNetCore.Server.Kestrel.Core.dll!Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.Http2Connection.ProcessRequestsAsync(Microsoft.AspNetCore.Hosting.Server.IHttpApplication application) Line 409
Microsoft.AspNetCore.Server.Kestrel.Core.dll!Microsoft.AspNetCore.Server.Kestrel.Core.Internal.HttpConnection.ProcessRequestsAsync(Microsoft.AspNetCore.Hosting.Server.IHttpApplication httpApplication) Line 109
Microsoft.AspNetCore.Server.Kestrel.Core.dll!Microsoft.AspNetCore.Server.Kestrel.Https.Internal.HttpsConnectionMiddleware.OnConnectionAsync(Microsoft.AspNetCore.Connections.ConnectionContext context) Line 227
Microsoft.AspNetCore.Server.Kestrel.Core.dll!Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.KestrelConnection.ExecuteAsync() Line 69
```

```
Microsoft.AspNetCore.Server.Kestrel.Core.dll!Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.Http2FrameWriter.WriteToOutputPipe() Line 149
System.Private.CoreLib.dll!System.Threading.Tasks.Task.Run
```

The second is somewhat irrelevant as it's just waiting for the connection to go away.

The object being awaited is a `StreamCloseAwaitable`, which is somehow reused for multiple streams in a single connection in a way I have yet to comprehend.

### Expected Behavior

_No response_

### Steps To Reproduce

The repro I'm aware of is a simulated Rapid Reset attack.

### Exceptions (if any)

_No response_

### .NET Version

8.0 RC2 and, presumably, main

### Anything else?

_No response_

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.