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

NRE in realtime-session-with-stacks line 123 #4

Open
desdesdes opened this issue Mar 27, 2024 · 4 comments
Open

NRE in realtime-session-with-stacks line 123 #4

desdesdes opened this issue Mar 27, 2024 · 4 comments

Comments

@desdesdes
Copy link

Hi Brian,

Thanks for this great example. I sometimes got an NullReferenceException then running the code on program.cs line 123. After I replaced line 122 to 124 with the code below and the exception was fixed.

Task.Factory.StartNew((o) =>
{
    var localCurrent = (TraceCallStack)o;
    ResolveSymbolsForModule(localCurrent.CodeAddress.CodeAddresses, localCurrent.CodeAddress.ModuleFile);
}, current);

Best regards,
Bart Vries

@brianrob
Copy link
Owner

Thanks for reporting this @desdesdes. I'm not able to repro this. How commonly do you see this, and are you still running against .NET 6 as the current repro does? Your change seems reasonable, but I would have expected localCurrent to be properly captured here.

@desdesdes
Copy link
Author

Hi Brian,

It was indeed the case that i was running against .net8! I tested it and the problem is reproducible in this repo if i change the targetframework from net6.0 to net8.0 in realtime-session-with-stacks.csproj, but not in the net6 version.

Best regards,
Bart Vries

@brianrob
Copy link
Owner

brianrob commented Apr 1, 2024

Thanks @desdesdes. I just tried running this against .NET 8, but I can't seem to repro the failure. How often were you seeing the failure? I'm wondering if you might be able to share a process dump of the failure. I am happy to take your change assuming it's the right thing, but I want to make sure there isn't a hidden GC hole or something like that here.

@desdesdes
Copy link
Author

desdesdes commented Apr 10, 2024

Hi Brain,

The main issue is that the NRE is thrown on a async background task and because of the behavior in .net core the exception on async background task swallowed by default. This behavior is documented here and here under remarks.

So you will only see the exception when you use a debugger or when you handle TaskScheduler.UnobservedTaskException.

I have build a quick repro to run with a debugger attached here.

If you like I can create a dump, but because the exception is swallowed it will be a first chance exception dump.

Best regards,
Bart Vries

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