DataDog / dd-trace-dotnet

.NET Client Library for Datadog APM

Home Page:https://docs.datadoghq.com/tracing/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

AspNetCore OutputCacheMiddleware throws NullReferenceException from BlockingMIddleware

aviram-zuzut-glbe opened this issue · comments

I added OutputCache attributes to a few controllers in my service, and I see this issue occurs a lot since then -

System.NullReferenceException: Object reference not set to an instance of an object.
at Microsoft.AspNetCore.OutputCaching.OutputCacheMiddleware.TryServeCachedResponseAsync(OutputCacheContext context, OutputCacheEntry cacheEntry, IReadOnlyList1 policies) at Microsoft.AspNetCore.OutputCaching.OutputCacheMiddleware.InvokeAwaited(HttpContext httpContext, IReadOnlyList1 policies)
at Datadog.Trace.ClrProfiler.AutoInstrumentation.AspNetCore.BlockingMiddleware.Invoke(HttpContext context) in /project/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/AspNetCore/BlockingMiddleware.cs:line 140
at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
at Datadog.Trace.ClrProfiler.AutoInstrumentation.AspNetCore.BlockingMiddleware.Invoke(HttpContext context) in /project/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/AspNetCore/BlockingMiddleware.cs:line 140
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequests[TContext](IHttpApplication`1 application)

To Reproduce
Add OutputCache attribute to an endpoint
example - [OutputCache(PolicyName = "DefaultCachePolicy", Duration = 300, VaryByQueryKeys = new[] { "*" }, VaryByHeaderNames = new[] { "Accept-Language" })]

Expected behavior
I will not see this issue appear.

Runtime environment (please complete the following information):

  • Instrumentation mode: automatic
  • Tracer version: not sure
  • OS: [mcr.microsoft.com/dotnet/aspnet:7.0.17-bullseye-slim]
  • CLR: [NET 7.0]
commented

Hi there,

We can't seem to reproduce the issue with the OutputCache attribute. Datadog.Trace.ClrProfiler.AutoInstrumentation.AspNetCore.BlockingMiddleware is expected to appear in the call stack in any case, which doesn't mean it's responsible for the exception thrown. Besides, the OutputCacheMiddleware already caused NullReferenceExceptions in the past, as we can see on the last fix for it.

Could you try running the application without the tracer and see if the exception is still happening?

Hey Anna, thanks for replying!
I checked and the errors are thrown only by DataDog tracer(I have dozens of calls per day, the issue does not appear besides DataDog). Also, I already updated my .net version to 7.0.17-bullseye-slim, this version should cover this issue already.

commented

Hi again,
I would suggest you contact support directly at https://www.datadoghq.com/support/ so we can fetch all the necessary details and go through your case.
Thank you