diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/slskd/Application.cs | 2 | ||||
| -rw-r--r-- | src/slskd/Program.cs | 11 | ||||
| -rw-r--r-- | src/slskd/Shares/SharedFileCache.cs | 2 |
3 files changed, 14 insertions, 1 deletions
diff --git a/src/slskd/Application.cs b/src/slskd/Application.cs index 25696de3..abb2e7b3 100644 --- a/src/slskd/Application.cs +++ b/src/slskd/Application.cs @@ -94,6 +94,7 @@ namespace slskd Console.CancelKeyPress += (_, args) => { ShuttingDown = true; + Program.MasterCancellationTokenSource.Cancel(); Log.Warning("Received SIGINT"); }; @@ -102,6 +103,7 @@ namespace slskd PosixSignalRegistration.Create(signal, context => { ShuttingDown = true; + Program.MasterCancellationTokenSource.Cancel(); Log.Fatal("Received {Signal}", signal); }); } diff --git a/src/slskd/Program.cs b/src/slskd/Program.cs index e828f242..94624115 100644 --- a/src/slskd/Program.cs +++ b/src/slskd/Program.cs @@ -30,6 +30,7 @@ namespace slskd using System.Security.Cryptography.X509Certificates; using System.Text; using System.Text.Json.Serialization; + using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.AspNetCore.Builder; @@ -189,6 +190,16 @@ namespace slskd /// </summary> public static ConcurrentFixedSizeQueue<LogRecord> LogBuffer { get; } = new ConcurrentFixedSizeQueue<LogRecord>(size: 100); + /// <summary> + /// Gets the master cancellation token source for the program. + /// </summary> + /// <remarks> + /// The token from this source should be used (or linked) to any long-running asynchronous task, so that when the application + /// begins to shut down these tasks also shut down in a timely manner. Actions that control the lifecycle of the program + /// (POSIX signals, a restart from the API, etc) should cancel this source. + /// </remarks> + public static CancellationTokenSource MasterCancellationTokenSource { get; } = new CancellationTokenSource(); + private static IConfigurationRoot Configuration { get; set; } private static OptionsAtStartup OptionsAtStartup { get; } = new OptionsAtStartup(); private static ILogger Log { get; set; } = new ConsoleWriteLineLogger(); diff --git a/src/slskd/Shares/SharedFileCache.cs b/src/slskd/Shares/SharedFileCache.cs index 0fb3c2d0..dd399e68 100644 --- a/src/slskd/Shares/SharedFileCache.cs +++ b/src/slskd/Shares/SharedFileCache.cs @@ -157,7 +157,7 @@ namespace slskd.Shares throw new ShareScanInProgressException("Shared files are already being scanned."); } - CancellationTokenSource = new CancellationTokenSource(); + CancellationTokenSource = CancellationTokenSource.CreateLinkedTokenSource(Program.MasterCancellationTokenSource.Token); var cancellationToken = CancellationTokenSource.Token; try |
