Proper shutdown on linux
MODIFY
WalletWasabi/Services/Terminate/TerminateService.cs
WalletWasabi/Services/Terminate/TerminateService.cs
using Microsoft.Win32;
using System;
using System.Runtime.InteropServices;
+using System.Runtime.Loader;
using System.Threading;
using System.Threading.Tasks;
using WalletWasabi.Logging;
@@ -22,6 +23,8 @@ namespace WalletWasabi.Services.Terminate
TerminateApplicationAsync = terminateApplicationAsync;
AppDomain.CurrentDomain.ProcessExit += CurrentDomain_ProcessExit;
Console.CancelKeyPress += Console_CancelKeyPress;
+ AssemblyLoadContext.Default.Unloading += Default_Unloading;
+ AppDomain.CurrentDomain.DomainUnload += CurrentDomain_DomainUnload;
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
@@ -29,6 +32,18 @@ namespace WalletWasabi.Services.Terminate
}
}
+ private void CurrentDomain_DomainUnload(object? sender, EventArgs e)
+ {
+ Logger.LogInfo($"Process domain unloading requested by the OS.");
+ Terminate();
+ }
+
+ private void Default_Unloading(AssemblyLoadContext obj)
+ {
+ Logger.LogInfo($"Process context unloading requested by the OS.");
+ Terminate();
+ }
+
private void Windows_SystemEvents_SessionEnding(object sender, SessionEndingEventArgs e)
{
// This event will only be triggered if you run Wasabi from the published package. Use the packager with --onlybinaries option.
@@ -99,6 +114,8 @@ namespace WalletWasabi.Services.Terminate
AppDomain.CurrentDomain.ProcessExit -= CurrentDomain_ProcessExit;
Console.CancelKeyPress -= Console_CancelKeyPress;
SystemEvents.SessionEnding -= Windows_SystemEvents_SessionEnding;
+ AssemblyLoadContext.Default.Unloading -= Default_Unloading;
+ AppDomain.CurrentDomain.DomainUnload -= CurrentDomain_DomainUnload;
// Indicate that the termination procedure finished. So other callers can return.
Interlocked.Exchange(ref _terminateStatus, TerminateStatusFinished);

Proper shutdown on linux