Skip to content

Commit

Permalink
Avoid unhandled exception handlers logging into disposed sawmills on …
Browse files Browse the repository at this point in the history
…shutdown

This caused a crash & exception swallow on Salamander.
  • Loading branch information
PJB3005 committed Nov 11, 2024
1 parent 4e100d9 commit 21c3535
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions Robust.Server/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,29 @@ internal static void SetupLogging(IDependencyCollection deps)
AppDomain.CurrentDomain.UnhandledException += (sender, args) =>
{
var message = ((Exception) args.ExceptionObject).ToString();
uh.Log(args.IsTerminating ? LogLevel.Fatal : LogLevel.Error, message);
try
{
uh.Log(args.IsTerminating ? LogLevel.Fatal : LogLevel.Error, message);
}
catch (ObjectDisposedException)
{
// Avoid eating the exception if it's during shutdown and the sawmill is already gone.
System.Console.WriteLine($"UnhandledException but sawmill is disposed! {message}");
}
};

var uo = mgr.GetSawmill("unobserved");
TaskScheduler.UnobservedTaskException += (sender, args) =>
{
uo.Error(args.Exception!.ToString());
try
{
uo.Error(args.Exception!.ToString());
}
catch (ObjectDisposedException)
{
// Avoid eating the exception if it's during shutdown and the sawmill is already gone.
System.Console.WriteLine($"UnobservedTaskException but sawmill is disposed! {args.Exception}");
}
#if EXCEPTION_TOLERANCE
args.SetObserved(); // don't crash
#endif
Expand Down

0 comments on commit 21c3535

Please sign in to comment.