From ffb43e18f389a85a7dd4d4c3dee5faca40b90977 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 13 Jul 2025 17:20:02 -0500 Subject: refine handling of OperationCanceledException --- src/slskd/Search/SearchService.cs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'src') 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 -- cgit v1.2.3