aboutsummaryrefslogtreecommitdiffstats
path: root/src/slskd/Search/SearchService.cs
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2025-07-13 17:20:02 -0500
committerJP Dillingham <jp@dillingham.me>2025-07-13 17:20:02 -0500
commitffb43e18f389a85a7dd4d4c3dee5faca40b90977 (patch)
tree7e89c9b4e01d732733a194f01756cf26630302b6 /src/slskd/Search/SearchService.cs
parentd4c631f853073c2eab91e428d912d931a293fd9a (diff)
downloadslskd-ffb43e18f389a85a7dd4d4c3dee5faca40b90977.tar.gz
refine handling of OperationCanceledException
Diffstat (limited to 'src/slskd/Search/SearchService.cs')
-rw-r--r--src/slskd/Search/SearchService.cs18
1 files changed, 12 insertions, 6 deletions
diff --git a/src/slskd/Search/SearchService.cs b/src/slskd/Search/SearchService.cs
index a828cfa6..d542b65a 100644
--- a/src/slskd/Search/SearchService.cs
+++ b/src/slskd/Search/SearchService.cs
@@ -318,14 +318,20 @@ namespace slskd.Search
Log.Debug("Search for '{Query}' ended normally (id: {Id})", query, id);
}
- catch (OperationCanceledException)
- {
- search.State = SearchStates.Completed | SearchStates.Cancelled;
- }
catch (Exception ex)
{
- Log.Error(ex, "Failed to execute search for '{Query}' (id: {Id}): {Message}", query, id, ex.Message);
- search.State = SearchStates.Completed | SearchStates.Errored;
+ // OperationCanceledException might be thrown somewhere deeper, and we don't want that to count.
+ // a search that was actually cancelled by the user will meet the criteria below.
+ if (ex is OperationCanceledException && cancellationTokenSource.Token.IsCancellationRequested)
+ {
+ Log.Information("Search for '{Query}' was cancelled");
+ search.State = SearchStates.Completed | SearchStates.Cancelled;
+ }
+ else
+ {
+ Log.Error(ex, "Failed to execute search for '{Query}' (id: {Id}): {Message}", query, id, ex.Message);
+ search.State = SearchStates.Completed | SearchStates.Errored;
+ }
}
// todo: remove this once we're sure the problem is fixed