Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AspNetCore OutputCacheMiddleware throws NullReferenceException from BlockingMIddleware #5440

Open
aviram-zuzut-glbe opened this issue Apr 15, 2024 · 3 comments

Comments

@aviram-zuzut-glbe
Copy link

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]
@anna-git
Copy link
Contributor

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?

@aviram-zuzut-glbe
Copy link
Author

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.

@anna-git
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants