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.

Exceptions on background thread are not handled and reported correctly

See original GitHub issue

Environment

How do you use Sentry? sentry.io

Which version of the SDK? 0.20.1

How did you install the package? UPM, git-url

Which version of Unity? 2021.3.6f1 LTS

Is this happening in Unity (editor) or on a player like Android, iOS, Windows? Reproduced in Windows Editor and Windows Player

Steps to Reproduce

  1. Create a new empty Unity project.
  2. Import sentry-unity 0.20.1 in UPM.
  3. Attach the code below to a GameObject
  4. Start the game
  5. Throw some exceptions in a background thread (click the in-game button).

Expected Result

Exceptions are reported as events to sentry.io

Actual Result

Only the first exception is handled and reported correctly.

Something seems to go wrong within the SDK, because after the first exception, subsequent exceptions do not result in any debug logs from Sentry, except a single “Sentry: (Info) Disposing the Hub”, which is directly followed by:

exception inside UnhandledException handler: (null) assembly:C:\Program Files\Unity\Hub\Editor\2021.3.6f1\Editor\Data\MonoBleedingEdge\lib\mono\unityjit-win32\mscorlib.dll type:Exception member:(null)

Code

using System;
using System.Threading;
using UnityEngine;

public class SentryTest : MonoBehaviour
{
	void OnGUI()
	{
		if (GUILayout.Button("Throw Exception On Background Thread"))
		{
			Debug.Log("Pressed button");
			var thread = new Thread(() =>
			{
				Thread.Sleep(1000);
				Debug.Log("Will throw exception");
				throw new Exception("Testing Background Thread Crash 2");
			});
			thread.Start();	
		}
	}
}

Any logs or screenshots

editor-log.txt

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
bitsandfoxescommented, Jul 11, 2022

@DrummerB thanks for raising this and providing the snippet. I can reproduce the issue locally and we’re going to take a look!

0reactions
DrummerBcommented, Jul 21, 2022

Great, thanks for the fix!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why unhandled exception in a background thread doesnt ...
This is happening because the BeginInvoke uses ThreadPool internally and when ThreadPool any unhadled exceptions will be silence fail.
Read more >
How to Handle Exceptions from Background Worker ...
Exceptions raised within the worker thread are not passed on to the thread which has initiated the work, which turns out to be...
Read more >
Exceptions of background threads
Are you sure the library has no way of handling or reporting errors? I have worked with a library that does not allow...
Read more >
877 – Unhandled Exceptions on Background Threads
When the background thread throws an exception and we don't handle it, the entire application (rather than just the background thread) is ...
Read more >
How to make thread-safe calls to controls - Windows Forms ...
To make a thread-safe call by using BackgroundWorker, handle the DoWork event. There are two events the background worker uses to report status: ......
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