Unexpected end of request content Kestrel ASP.NET Core

14,568

When I run this request as part of WCF contract in WebApi1 I got stacktrace:

   at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
   at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
   at System.Threading.Tasks.Task`1.get_Result()

However I noticed that Exception was thrown always after 2 minutes...

Than I tried to send that 20GB file as part of controller method (from WebAPI1) and catched there TaskCanceledException. When this exception occurs, we can tell was that a timeout issue by checking the flag IsCancellationRequested if it is false it means that it is timeout issue. Helpful post here: HttpClient - A task was cancelled?

In my case TaskCanceledException in stacktrace was set to false, so it was timeout in HttpClient

new HttpClient { Timeout = TimeSpan.FromMinutes(2) };

increasing the limit to 10 minutes resolved the issue.

Share:
14,568
Reven
Author by

Reven

Updated on June 19, 2022

Comments

  • Reven
    Reven almost 2 years

    I have a problem with sending large (20GB) file between two WebApi.

    WebAPI1 written in ASP.NET 4.6

    WebAPI2 written in ASP.NET Core 2.0

    When I am sending this file via Postman to WebAPI2 whole file is send. But when I am trying to send the file from WebAPI1 to WebAPI2 it fails (I am able to send files like 7GB though).

    During sending 20GB file I am receiving error in WebAPI2:

    Microsoft.AspNetCore.Server.Kestrel.Core.BadHttpRequestException: Unexpected
     end of request content.
       at Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.PipeCompl
    etion.ThrowFailed()
       at Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.Pipe.GetR
    esult(ReadResult& result)
       at Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.Pipe.Micr
    osoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.IReadableBufferAwai
    ter.GetResult()
       at Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.ReadableB
    ufferAwaitable.GetResult()
       at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.MessageBody.<ReadAs
    ync>d__22.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNot
    ification(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
       at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.FrameRequestStream.
    <ReadAsyncInternal>d__21.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNot
    ification(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
       at Microsoft.AspNetCore.WebUtilities.BufferedReadStream.<EnsureBufferedAsync>
    d__37.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNot
    ification(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
       at Microsoft.AspNetCore.WebUtilities.MultipartReaderStream.<ReadAsync>d__36.M
    oveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNot
    ification(Task task)
       at System.IO.Stream.<CopyToAsyncInternal>d__27.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNot
    ification(Task task)