Skip to content

Unobserved Task Exception incorrectly causes session to end as crashed #2104

Closed
@mattjohnsonpint

Description

@mattjohnsonpint

When capturing events, we look to see if any unhandled exceptions have occurred and if so we end the session and mark it as crashed.

var hasUnhandledException = evt.HasUnhandledException();
if (hasUnhandledException)
{
// Event contains a terminal exception -> end session as crashed
_options.LogDebug("Ending session as Crashed, due to unhandled exception.");
actualScope.SessionUpdate = _sessionManager.EndSession(SessionEndStatus.Crashed);
}
else if (evt.HasException())
{
// Event contains a non-terminal exception -> report error
// (this might return null if the session has already reported errors before)
actualScope.SessionUpdate = _sessionManager.ReportError();
}

This is a problem if the unhandled exception did not actually cause the application to crash, which happens in the case of an exception in an unobserved task.

ex.Data[Mechanism.HandledKey] = false;
ex.Data[Mechanism.MechanismKey] = "UnobservedTaskException";

We should only end the session if indeed the application is terminating.

Affects Unity also, as per discussion with @bitsandfoxes.

Relates to getsentry/rfcs#10 - but shouldn't depend on it being completed. (We can prevent the end of session whether or not we send that information to Sentry.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugSomething isn't working

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions