Apm-agent-dotnet: Upgrading Elastic.Apm.AspNetFullFramework from 1.6.1 to 1.7.1 breaks multipart async request body reading

Created on 7 Jan 2021  路  2Comments  路  Source: elastic/apm-agent-dotnet

Describe the bug
In our .net framework web app, targeting .net framework 4.8

To Reproduce
Steps to reproduce the behavior:

  1. Create a controller that implements System.Web.Http.ApiController
  2. Add and setup using default settings the Elastic.Apm.AspNetFullFramework v1.7.1 nuget package
  3. Make an async controller endpoint that makes a multipart async read await Request.Content.ReadAsMultipartAsync();

Expected behavior
I expect APM not to interfere with reading multipart async request streams, especially when we don't have Body capturing enabled.

Here is a stripped down stack trace:

Error reading MIME multipart body part.
System.IO.IOException: Error reading MIME multipart body part. [Source: System.Net.Http.Formatting]
    at System.Net.Http.HttpContentMultipartExtensions.d__9`1.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 <internal Service>.d__0.MoveNext() in <path to internal service source file>:line 14 --- 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 <internal ApiController>.d__8.MoveNext() in <path to internal ApiController source file>:line 77
Inner Exception:
System.InvalidOperationException: Unable to read the entity body in Bufferless mode. The request stream has already been buffered. [Source: System.Web.Http.WebHost]
    at System.Web.Http.WebHost.HttpControllerHandler.<>c__DisplayClass18_0.b__1()
    at System.Web.Http.WebHost.HttpControllerHandler.LazyStreamContent.get_StreamContent()
    at System.Web.Http.WebHost.HttpControllerHandler.LazyStreamContent.CreateContentReadStreamAsync()
    at System.Net.Http.HttpContent.ReadAsStreamAsync()
    at System.Net.Http.HttpContentMultipartExtensions.d__9`1.MoveNext()

Endpoint example

[Route]
public async Task<IHttpActionResult> Post()
{
    var content = await Request.Content.ReadAsMultipartAsync(); //exception gets thrown here
    return Ok(content.ToString()); 
}
bug agent-dotnet

All 2 comments

Added a reproduction scenario to the sample aspnetframework project:
https://github.com/elastic/apm-agent-dotnet/pull/1114

Thanks for reporting @WillGunn, I've opened https://github.com/elastic/apm-agent-dotnet/pull/1115 to address

Was this page helpful?
0 / 5 - 0 ratings

Related issues

fernandolamp picture fernandolamp  路  7Comments

nilsgstrabo picture nilsgstrabo  路  5Comments

kszymanski picture kszymanski  路  7Comments

v1v picture v1v  路  3Comments

rgmills picture rgmills  路  4Comments