title: ASP.NET Core throwing -4077 ECONNRESET if files total size in POST request are over 30MB
body: <p>I could not figure out why Kestrel keeps closing the connection when I try uploading large files to it, as soon as it gets over 30MB, to be precise.</p>
  
  <p>I am aware Kestrel has a default setting of 30MB in terms of maximum request size, and I have tried increasing the maximum request size to 100MB in the web.config file:</p>
  
  <pre><code>&lt;security&gt;
    &lt;requestFiltering allowDoubleEscaping="true"&gt;
      &lt;!-- This will handle requests up to 100MB --&gt;
      &lt;requestLimits maxAllowedContentLength="104857600" /&gt;
    &lt;/requestFiltering&gt;
  &lt;/security&gt;
  </code></pre>
  
  <p>I have tried configuring it when bootstrapping the server as well:</p>
  
  <pre><code>WebHost.UseKestrel(options =&gt; options.Limits.MaxRequestBodySize = 104857600) // 100MB
  </code></pre>
  
  <p>[...]</p>
  
  <pre><code>services.Configure&lt;FormOptions&gt;(options =&gt; options.MultipartBodyLengthLimit = 104857600); // 100MB
  </code></pre>
  
  <p>I have tried setting it in the middleware:</p>
  
  <pre><code>var maxRequestBodySizeFeature = httpContext.Features.Get&lt;IHttpMaxRequestBodySizeFeature&gt;();
  maxRequestBodySizeFeature.MaxRequestBodySize = 104857600;
  </code></pre>
  
  <p>I have tried everything I could find, for example what is suggested here:</p>
  
  <p><a href="https://stackoverflow.com/questions/38698350/increase-upload-file-size-in-asp-net-core/45927665">Increase upload file size in Asp.Net core</a></p>
  
  <p>And here:</p>
  
  <p><a href="https://www.talkingdotnet.com/how-to-increase-file-upload-size-asp-net-core/" rel="nofollow noreferrer">https://www.talkingdotnet.com/how-to-increase-file-upload-size-asp-net-core/</a></p>
  
  <p>But as soon as my POST request containing several files that together go over the 30MB limit, when the following line executes:</p>
  
  <pre><code>foreach (var entry in httpContext.Request.Form /* Exception is thrown by Form property */)
  {
  }
  </code></pre>
  
  <p>I get the following exception:</p>
  
  <pre><code>[Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal.ConnectionResetException] - Error -4077 ECONNRESET connection reset by peer
     at Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.PipeCompletion.ThrowFailed()
     at Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.Pipe.GetResult(ReadResult&amp; result)
     at Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.Pipe.Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.IReadableBufferAwaiter.GetResult()
     at Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.ReadableBufferAwaitable.GetResult()
     at Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.LibuvOutputConsumer.&lt;WriteOutputAsync&gt;d__6.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     at Microsoft.AspNetCore.WebUtilities.BufferedReadStream.&lt;EnsureBufferedAsync&gt;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.HandleNonSuccessAndDebuggerNotification(Task task)
     at Microsoft.AspNetCore.WebUtilities.MultipartReaderStream.&lt;ReadAsync&gt;d__36.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     at Microsoft.AspNetCore.WebUtilities.StreamHelperExtensions.&lt;DrainAsync&gt;d__3.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     at Microsoft.AspNetCore.WebUtilities.MultipartReader.&lt;ReadNextSectionAsync&gt;d__20.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     at Microsoft.AspNetCore.Http.Features.FormFeature.&lt;InnerReadFormAsync&gt;d__18.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     at Microsoft.AspNetCore.Http.Features.FormFeature.ReadForm()
  [...]
  </code></pre>
  
  <p>As far as I know, this is not the browser closing the connection. In the browser, I just select a bunch of files and upload them, and immediately in Visual Studio, the exception is thrown. Everything is done in localhost.</p>