Aspnetcore: WEB API Controller method return value causes net::ERR_INCOMPLETE_CHUNKED_ENCODING

Created on 26 Mar 2019  路  3Comments  路  Source: dotnet/aspnetcore

Describe the bug

When we moved to .NET Core 3 controllers stopped working properly. When method from controller returns data (e.g string) of size >= 4099 it causes net::ERR_INCOMPLETE_CHUNKED_ENCODING in chrome.
Tried on preview 3 and preview 4, on .NET Core 2.2 everything was good.
No issues when method returns data <=4098.

To Reproduce

Method of controller causing this behavior:

[HttpGet("TestControllerResponse")]
public IActionResult TestControllerResponse()
{
     string result = "";
     var i = 0;
     //var size = 4098;    // 4098 -> OK
     var size = 4099;    // 4099 -> net::ERR_INCOMPLETE_CHUNKED_ENCODING
     while (++i <= size)
     {
          result = $"{result}+";
     }
     return Ok(result);
}

Expected behavior

As in previous versions, this should be OK, not causing net::ERR_INCOMPLETE_CHUNKED_ENCODING.

Details from uncaught exceptions:

fail: Microsoft.AspNetCore.Server.Kestrel[13]
Connection id "0HLLHQ2L5SQMD", Request id "0HLLHQ2L5SQMD:0000000E": An unhandled exception was thrown by the application.
System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
at System.Memory1.Slice(Int32 start, Int32 length) at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.Http1OutputProducer.GetChunkedMemory(Int32 sizeHint) at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.Http1OutputProducer.GetSpan(Int32 sizeHint) at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.GetSpan(Int32 sizeHint) at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpResponsePipeWriter.GetSpan(Int32 sizeHint) at Microsoft.AspNetCore.Http.HttpResponseWritingExtensions.WriteMultiSegmentEncoded(PipeWriter writer, String text, Encoding encoding, Span1 destination, Int32 encodedLength)
at Microsoft.AspNetCore.Http.HttpResponseWritingExtensions.Write(HttpResponseresponse, String text, Encoding encoding)
at Microsoft.AspNetCore.Http.HttpResponseWritingExtensions.WriteAsync(HttpResponse response, String text, Encoding encoding, CancellationToken cancellationToken)
at Microsoft.AspNetCore.Mvc.Formatters.StringOutputFormatter.WriteResponseBodyAsync(OutputFormatterWriteContext context, Encoding encoding)
at Microsoft.AspNetCore.Mvc.Formatters.TextOutputFormatter.WriteAsync(OutputFormatterWriteContext context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ObjectResultExecutor.ExecuteAsync(ActionContext context, ObjectResult result)
at Microsoft.AspNetCore.Mvc.ObjectResult.ExecuteResultAsync(ActionContext context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeResultAsync(IActionResult result)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeNextResultFilterAsyncTFilter,TFilterAsync
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResultExecutedContext context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.ResultNextTFilter,TFilterAsync
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeResultFilters()
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeNextResourceFilter()
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContext context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next,Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeFilterPipelineAsync()
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeAsync()
at Microsoft.AspNetCore.Routing.EndpointMiddleware.Invoke(HttpContext httpContext)
at Microsoft.AspNetCore.Routing.EndpointRoutingMiddleware.Invoke(HttpContexthttpContext)
at Microsoft.AspNetCore.Builder.Extensions.MapMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequestsTContext

Done area-servers bug servers-kestrel

Most helpful comment

@anurse bringing into preview4 and assigning to @jkotalik as a critical bug. We can load balance in triage.

All 3 comments

This is also being reported over here: https://github.com/domaindrivendev/Swashbuckle.AspNetCore/pull/1082

@jkotalik

@anurse bringing into preview4 and assigning to @jkotalik as a critical bug. We can load balance in triage.

Let's just say @Tratcher and I are shocked that this wasn't caught by a test beforehand...

Was this page helpful?
0 / 5 - 0 ratings