Skip to content

ConnectionAbortedException ---> Reading is already in progress #52324

Open
@Transis-Felipe

Description

@Transis-Felipe

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

image

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-networkingIncludes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractionsfeature-kestrel

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions