We're using nightly nuget packages 2013-03-30. When we're trying to upload large files (for instance > 2Mb) and process it by using HttpContentMultipartExtensions we've got unhandled exception which crashes AppDomain:
"An unhandled exception of type 'System.StackOverflowException' occurred in Unknown Module."
Code sample is straightforward and looks like http://www.asp.net/web-api/overview/working-with-http/sending-html-form-data,-part-2
After research we've found that in MoveToNextSegmentAsync method exists recursive call:
```
private static async Task<bool> MoveToNextSegmentAsync(MultipartAsyncContext context)
{
...
if (!await MoveToNextSegmentAsync(context))
{
await MoveToNextPartAsync(context);
}
...
}
```
It was commited by phenning on Feb 26, 2013. Commit 83169ad25a4c:
http://aspnetwebstack.codeplex.com/SourceControl/changeset/83169ad25a4cbdd99b5f80009a5ad75e9c69de3e#src/System.Net.Http.Formatting/HttpContentMultipartExtensions.cs
When large http body is processing this code fragment creates a really huge call stack which causes StackOverflowException and AppDomain crash.
Comments: Hello, Henrik, Let me tell a short story. We caught few issues in load testing of our web application with >100 rps where HttpContentMultipartExtensions throws exceptions in about 1% of requests: ``` "Error reading MIME multipart body part." Inner message: "The client disconnected." ``` It was reproduced in IIS 7.5 & 8 and only without debugging at the local machines and in the Azure Cloud. System.Net.Http.Formatting library was used from latest stable nuget package http://nuget.org/packages/Microsoft.AspNet.WebApi.Client. After code review of v4 HttpContentMultipartExtensions we found that in this static class exists next suspicious static members: ``` private static readonly AsyncCallback _onMultipartReadAsyncComplete = new AsyncCallback(OnMultipartReadAsyncComplete); private static readonly AsyncCallback _onMultipartWriteSegmentAsyncComplete = new AsyncCallback(OnMultipartWriteSegmentAsyncComplete); ``` As a result we started afraid of this code fragment :) and found a new v5 branch of Web API where HttpContentMultipartExtensions was refactored by phenning. This version passed our smoke tests without strange "Error reading MIME multipart body part." exceptions, but our qa team tests was not passed because they use much more larger files.
"An unhandled exception of type 'System.StackOverflowException' occurred in Unknown Module."
Code sample is straightforward and looks like http://www.asp.net/web-api/overview/working-with-http/sending-html-form-data,-part-2
After research we've found that in MoveToNextSegmentAsync method exists recursive call:
```
private static async Task<bool> MoveToNextSegmentAsync(MultipartAsyncContext context)
{
...
if (!await MoveToNextSegmentAsync(context))
{
await MoveToNextPartAsync(context);
}
...
}
```
It was commited by phenning on Feb 26, 2013. Commit 83169ad25a4c:
http://aspnetwebstack.codeplex.com/SourceControl/changeset/83169ad25a4cbdd99b5f80009a5ad75e9c69de3e#src/System.Net.Http.Formatting/HttpContentMultipartExtensions.cs
When large http body is processing this code fragment creates a really huge call stack which causes StackOverflowException and AppDomain crash.
Comments: Hello, Henrik, Let me tell a short story. We caught few issues in load testing of our web application with >100 rps where HttpContentMultipartExtensions throws exceptions in about 1% of requests: ``` "Error reading MIME multipart body part." Inner message: "The client disconnected." ``` It was reproduced in IIS 7.5 & 8 and only without debugging at the local machines and in the Azure Cloud. System.Net.Http.Formatting library was used from latest stable nuget package http://nuget.org/packages/Microsoft.AspNet.WebApi.Client. After code review of v4 HttpContentMultipartExtensions we found that in this static class exists next suspicious static members: ``` private static readonly AsyncCallback _onMultipartReadAsyncComplete = new AsyncCallback(OnMultipartReadAsyncComplete); private static readonly AsyncCallback _onMultipartWriteSegmentAsyncComplete = new AsyncCallback(OnMultipartWriteSegmentAsyncComplete); ``` As a result we started afraid of this code fragment :) and found a new v5 branch of Web API where HttpContentMultipartExtensions was refactored by phenning. This version passed our smoke tests without strange "Error reading MIME multipart body part." exceptions, but our qa team tests was not passed because they use much more larger files.