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

UnobservedTaskExceptionIntegration could provide a stack trace (but doesn't) #2065

Closed
dbruning opened this issue Nov 25, 2022 · 3 comments · Fixed by #2067
Closed

UnobservedTaskExceptionIntegration could provide a stack trace (but doesn't) #2065

dbruning opened this issue Nov 25, 2022 · 3 comments · Fixed by #2067
Assignees
Labels
Bug Something isn't working

Comments

@dbruning
Copy link

Package

Sentry.AspNetCore

.NET Flavor

.NET

.NET Version

6.0.11

OS

Windows

SDK Version

3.24.0

Self-Hosted Sentry Version

No response

Steps to Reproduce

  1. Cause an UnobservedTaskException in a Blazor event handler, e.g.:
protected void CauseUnobservedTaskException()
	{
		// Task.Run(() => throw new ArgumentException("Test unobserved task exception from Blazor poke page"));
		var task = Task.Factory.StartNew(() =>
		{
			Thread.Sleep(1000); // emulate some calculation
			throw new Exception("Test unobserved task exception from Blazor poke page");
		});

			Thread.Sleep(2000); // emulate some calculation
		task = null;
		GC.Collect();
		GC.WaitForPendingFinalizers();
		GC.Collect();
	}
  1. Allow Sentry's default handling to report the error

Expected Result

Issue in Sentry should have a useful stack trace to the cause of the error

Actual Result

Issue in Sentry doesn't have a stack trace.

If I turn off Sentry's handling, e.g.:

webBuilder.UseSentry(sentryOptions =>
{
   sentryOptions.Dsn = ...;
   sentryOptions.DisableUnobservedTaskExceptionCapture();
});

... and add my own code like this:

TaskScheduler.UnobservedTaskException += (sender, e) =>
{
	// Report the inner exception, to get the stack trace
	SentrySdk.CaptureException(e.Exception.InnerException);
};

... then I get a stack trace in Sentry. Could the built-in UnobservedTaskException do this, or something else clever to report the stack trace? Otherwise it's really difficult to debug these issues.

@mattjohnsonpint
Copy link
Contributor

Thanks. I will take a look.

@mattjohnsonpint
Copy link
Contributor

This appears to be a regression, caused by #1922 which fixed #1917. Basically, we had assumed that the aggregate exception was always going to be the source of the stack trace, but in this case the inner exception already has it.

Fix forthcoming.

@dbruning
Copy link
Author

dbruning commented Dec 7, 2022

Thankyou!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants