From 500ea27c3b9e027ed114d45587dde9108b0912ee Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sat, 24 Sep 2022 12:43:56 -0500 Subject: await scan start --- src/slskd/Application.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/slskd/Application.cs') diff --git a/src/slskd/Application.cs b/src/slskd/Application.cs index 20735ead..25696de3 100644 --- a/src/slskd/Application.cs +++ b/src/slskd/Application.cs @@ -384,7 +384,7 @@ namespace slskd else { // todo: should this be forced prior to connection if the cache can't be loaded? - _ = Shares.StartScanAsync(); + await Shares.StartScanAsync(); } } -- cgit v1.2.3 From c447c545257721398ac0576c07d4873156c5a19e Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sat, 24 Sep 2022 16:20:21 -0500 Subject: add and use MasterCancellationTokenSource --- src/slskd/Application.cs | 2 ++ src/slskd/Program.cs | 11 +++++++++++ src/slskd/Shares/SharedFileCache.cs | 2 +- 3 files changed, 14 insertions(+), 1 deletion(-) (limited to 'src/slskd/Application.cs') 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 /// public static ConcurrentFixedSizeQueue LogBuffer { get; } = new ConcurrentFixedSizeQueue(size: 100); + /// + /// Gets the master cancellation token source for the program. + /// + /// + /// 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. + /// + 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 -- cgit v1.2.3 From 721a1436960746df84410cfb4b6626f50df62f43 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sat, 24 Sep 2022 16:20:58 -0500 Subject: don't wait for scan to complete on start --- src/slskd/Application.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/slskd/Application.cs') diff --git a/src/slskd/Application.cs b/src/slskd/Application.cs index abb2e7b3..62138d48 100644 --- a/src/slskd/Application.cs +++ b/src/slskd/Application.cs @@ -386,7 +386,7 @@ namespace slskd else { // todo: should this be forced prior to connection if the cache can't be loaded? - await Shares.StartScanAsync(); + _ = Shares.ScanAsync(); } } -- cgit v1.2.3 From c42c892408faf7481d111e866a654ea37866d94b Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sat, 24 Sep 2022 16:22:26 -0500 Subject: report progress every 1% instead of 5 --- src/slskd/Application.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/slskd/Application.cs') diff --git a/src/slskd/Application.cs b/src/slskd/Application.cs index 62138d48..4990186e 100644 --- a/src/slskd/Application.cs +++ b/src/slskd/Application.cs @@ -1035,7 +1035,7 @@ namespace slskd var lastProgress = Math.Round(previous.ScanProgress * 100); var currentProgress = Math.Round(current.ScanProgress * 100); - if (lastProgress != currentProgress && Math.Round(currentProgress, 0) % 5d == 0) + if (lastProgress != currentProgress && Math.Round(currentProgress, 0) % 1d == 0) { State.SetValue(s => s with { Shares = current }); Log.Information("Scanned {Percent}% of shared directories. Found {Files} files so far.", currentProgress, current.Files); -- cgit v1.2.3 From a4fcf65d451e9c2629f9f113ca06485b7e564f8e Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sat, 24 Sep 2022 17:32:45 -0500 Subject: fix state bug --- src/slskd/Application.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/slskd/Application.cs') diff --git a/src/slskd/Application.cs b/src/slskd/Application.cs index 4990186e..86d74d4d 100644 --- a/src/slskd/Application.cs +++ b/src/slskd/Application.cs @@ -986,6 +986,8 @@ namespace slskd { var (previous, current) = state; + Console.WriteLine(current); + if (!previous.Scanning && current.Scanning) { // the scan is starting @@ -1025,7 +1027,7 @@ namespace slskd else if (!previous.Ready && current.Ready) { // the share transitioned into ready without completing a scan; it was loaded from disk - State.SetValue(state => state with { Shares = state.Shares with { ScanPending = false } }); + State.SetValue(state => state with { Shares = current with { ScanPending = false } }); Log.Information("Share cache loaded from disk successfully. Sharing {Directories} directories and {Files} files", current.Directories, current.Files); _ = CacheBrowseResponse(); } -- cgit v1.2.3 From 052524a14612d08823b31696d0c35b66bcc066b5 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sat, 24 Sep 2022 17:35:05 -0500 Subject: foce a scan at start if the cache can't be loaded from disk --- src/slskd/Application.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/slskd/Application.cs') diff --git a/src/slskd/Application.cs b/src/slskd/Application.cs index 86d74d4d..bc3892d9 100644 --- a/src/slskd/Application.cs +++ b/src/slskd/Application.cs @@ -385,8 +385,7 @@ namespace slskd } else { - // todo: should this be forced prior to connection if the cache can't be loaded? - _ = Shares.ScanAsync(); + await Shares.ScanAsync(); } } -- cgit v1.2.3 From fa8f8cb6829571cb2d7c1d81b99e88d0e2177195 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 25 Sep 2022 14:22:28 -0500 Subject: remove debug --- src/slskd/Application.cs | 2 -- 1 file changed, 2 deletions(-) (limited to 'src/slskd/Application.cs') diff --git a/src/slskd/Application.cs b/src/slskd/Application.cs index bc3892d9..f517850b 100644 --- a/src/slskd/Application.cs +++ b/src/slskd/Application.cs @@ -985,8 +985,6 @@ namespace slskd { var (previous, current) = state; - Console.WriteLine(current); - if (!previous.Scanning && current.Scanning) { // the scan is starting -- cgit v1.2.3