question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

System.NullReferenceException in /_/src/Sentry.AspNetCore/SentryMiddleware.cs in roughly 1 in 100 requests

See original GitHub issue

Environment

Sentry SaaS (sentry.io) Sentry SDK: .NET 3.3.4 Framework: ASP.NET Core 5.0 Deployed to Azure Web Apps

Steps to Reproduce

This issue only occurs sporadically (1 in 100 requests) and has only occurred 2 days after upgrading to 3.3.4. I wasn’t able to reproduce this issue locally and so far has only occured on our Azure hosted instances.

  1. Inside Program.Main() we call webBuilder.UseSentry() with the generic .NET Host builder (source for reference)
  2. Inside our Controller we call SentrySdk.ConfigureScope() like so:
public async Task<ActionResult<FullLessonData>> FetchLessonByLessonID(long lessonID)
{
    var (status, lesson) = await _lessonModelGenerator.LessonByID(lessonID, User);
    SentrySdk.ConfigureScope(scope =>
    {
        scope.SetExtra("lessonModelGenerator.responseStatus", status.ToString());
    });
    return status switch
    {
        LessonModelGenerator.ResponseStatus.OK => lesson == null ? Forbid() : Ok(lesson),
        LessonModelGenerator.ResponseStatus.NoAccess => Forbid(),
        LessonModelGenerator.ResponseStatus.NotFound => NotFound(),
        _ => throw new NotImplementedException("LessonModelGenerator.ResponseStatus is not handled")
    };
}
  1. In roughly 1 in 100 requests, we receive a System.NullReferenceException in File "/_/src/Sentry.AspNetCore/SentryMiddleware.cs", line 139, col 9, in async Task SentryMiddleware.InvokeAsync(HttpContext context) (The full sentry log + callstack for reference.)

Expected Result

No exception is thrown during normal operations

Actual Result

Raw JSON of the sentry event that captures the exception including callstack

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:11 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
jan-auercommented, May 4, 2021

metadata indeed comes from the ingestion pipeline. It is generated here and written here. They are used by the Sentry UI to render issue titles among other things.

They are definitely unrelated to any SDK problems.

0reactions
SimonCroppcommented, Dec 28, 2021

@bruno-garcia so based on that, this should be closed as not related to sentry?

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I fix the error: System.NullReferenceException
A NullReferenceException exception is thrown when you try to access a member on a type whose value is null. A NullReferenceException exception ......
Read more >
Random NullReferenceException on Asp.Net Core 2.1.1 ...
For the majority of requests it works as expected. Randomly (approximately 1-5 out of 100 requests) it results in a NullReferenceException.
Read more >
Failed to extract body - NullReferenceException #1701
System.NullReferenceException: Object reference not set to an instance of an ... ExtractPayload(IHttpRequest request) in /_/src/Sentry/ ...
Read more >
object reference not set to an instance of an object.
Everything seems to work fine up until enabling the components, which I get a NullReferenceException in the console.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found