ConnectionAbortedException ---> Reading is already in progress
- Dominant language
- C#
- Stars
- 38.4k
- Forks
- 10.9k
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 290
Description
Describe the bug
We're frequently getting the exception below in .net 8.0.
Microsoft.AspNetCore.Connections.ConnectionAbortedException: The connection was aborted by the application.
---> System.InvalidOperationException: Reading is already in progress.
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.Http1MessageBody.OnConsumeAsync()
--- End of inner exception stack trace ---
Further technical details
ASP.NET Core 8.0
Kestrel on Windows Server 2019

https://github.com/dotnet/aspnetcore/blob/main/src/Servers/Kestrel/Core/src/Internal/Http/Http1MessageBody.cs
protected override Task OnConsumeAsync()
{
try
{
while (TryReadInternal(out var readResult))
{
AdvanceTo(readResult.Buffer.End);
if (readResult.IsCompleted)
{
return Task.CompletedTask;
}
}
}
catch (BadHttpRequestException ex)
{
// At this point, the response has already been written, so this won't result in a 4XX response;
// however, we still need to stop the request processing loop and log.
_context.SetBadRequestState(ex);
return Task.CompletedTask;
}
catch (InvalidOperationException ex)
{
var connectionAbortedException = new ConnectionAbortedException(CoreStrings.ConnectionAbortedByApplication, ex);
_context.ReportApplicationError(connectionAbortedException);
// Have to abort the connection because we can't finish draining the request
_context.StopProcessingNextRequest();
return Task.CompletedTask;
}
return OnConsumeAsyncAwaited();
}
One suggestion should be to implement TryMapGet to be called instead of app.MapGet on the server side.
Contributor guide
Assessment
This issue has not been assessed yet.