fix: terminate process if service unload fails

This commit is contained in:
goat 2023-05-22 21:01:37 +02:00
parent 880095428c
commit b80681e3e1
No known key found for this signature in database
GPG key ID: 49E2AA8C6A76498B

View file

@ -156,6 +156,8 @@ public sealed class EntryPoint
AppDomain.CurrentDomain.UnhandledException += OnUnhandledException;
TaskScheduler.UnobservedTaskException += OnUnobservedTaskException;
var unloadFailed = false;
try
{
if (info.DelayInitializeMs > 0)
@ -180,7 +182,15 @@ public sealed class EntryPoint
dalamud.WaitForUnload();
ServiceManager.UnloadAllServices();
try
{
ServiceManager.UnloadAllServices();
}
catch (Exception ex)
{
Log.Fatal(ex, "Could not unload services.");
unloadFailed = true;
}
}
catch (Exception ex)
{
@ -195,6 +205,11 @@ public sealed class EntryPoint
Log.CloseAndFlush();
SerilogEventSink.Instance.LogLine -= SerilogOnLogLine;
}
// If we didn't unload services correctly, we need to kill the process.
// We will never signal to Framework.
if (unloadFailed)
Environment.Exit(-1);
}
private static void SerilogOnLogLine(object? sender, (string Line, LogEvent LogEvent) ev)
@ -327,7 +342,7 @@ public sealed class EntryPoint
}
var pluginInfo = string.Empty;
var supportText = ", please visit us on Discord for more help.";
var supportText = ", please visit us on Discord for more help";
try
{
var pm = Service<PluginManager>.GetNullable();