aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2025-07-12 17:41:58 -0500
committerJP Dillingham <jp@dillingham.me>2025-07-12 17:41:58 -0500
commit69d039a015e2177d2713eea74b6d79fde1147ce7 (patch)
treede445d8ad57f2adfb45448a01b26cb3b2896cef2 /src
parent7f5ff0371bf920957096b18ce92a81992c0f3446 (diff)
downloadslskd-69d039a015e2177d2713eea74b6d79fde1147ce7.tar.gz
add diagnostics
Diffstat (limited to 'src')
-rw-r--r--src/slskd/Search/SearchService.cs26
1 files changed, 18 insertions, 8 deletions
diff --git a/src/slskd/Search/SearchService.cs b/src/slskd/Search/SearchService.cs
index 7d8fcf41..81f37640 100644
--- a/src/slskd/Search/SearchService.cs
+++ b/src/slskd/Search/SearchService.cs
@@ -257,6 +257,7 @@ namespace slskd.Search
// initialize the list of responses that we'll use to accumulate them
// populated by the responseHandler we pass to SearchAsync
List<SearchResponse> responses = new();
+ List<(SearchStates State, DateTime Timestamp, string Source)> stateTransitions = new();
options ??= new SearchOptions();
options = options.WithActions(
@@ -269,6 +270,8 @@ namespace slskd.Search
search = search.WithSoulseekSearch(args.Search);
Update(search);
+ stateTransitions.Add((args.Search.State, DateTime.UtcNow, "StateChangedDelegate"));
+
SearchHub.BroadcastUpdateAsync(search);
Log.Debug("Search for '{Query}' state changed: {State} (id: {Id})", query, search.State, id);
@@ -287,7 +290,6 @@ namespace slskd.Search
// note that we're not actually doing anything with the response here, that's happening in the
// response handler. we're only updating counts here.
SearchHub.BroadcastUpdateAsync(search);
- Update(search);
}));
// initiate the search. this can throw at invocation if there's a problem with
@@ -305,15 +307,17 @@ namespace slskd.Search
// update the search record to accurately reflect the final state
_ = Task.Run(async () =>
{
- var soulseekSearch = await soulseekSearchTask;
- search = search.WithSoulseekSearch(soulseekSearch);
-
- Log.Debug("Search for '{Query}' ended normally (id: {Id})", query, id);
- }, cancellationToken: cancellationTokenSource.Token)
- .ContinueWith(async task =>
- {
try
{
+ try
+ {
+ var soulseekSearch = await soulseekSearchTask;
+ stateTransitions.Add((SearchStates.None, DateTime.UtcNow, "Callsite")); // bogus entry to try and capture when it returned
+
+ search = search.WithSoulseekSearch(soulseekSearch);
+
+ Log.Debug("Search for '{Query}' ended normally (id: {Id})", query, id);
+ }
catch (OperationCanceledException)
{
search.State = SearchStates.Completed | SearchStates.Cancelled;
@@ -324,6 +328,12 @@ namespace slskd.Search
search.State = SearchStates.Completed | SearchStates.Errored;
}
+ if (!search.State.HasFlag(SearchStates.Completed))
+ {
+ Log.Warning("Gotcha! Search for '{Search}' concluded without the Completed flag. Time is now {Timestamp}. States: {States}", query.SearchText, DateTime.UtcNow, stateTransitions);
+ search.State |= SearchStates.Completed;
+ }
+
search.EndedAt = DateTime.UtcNow;
search.Responses = responses.Select(r => Response.FromSoulseekSearchResponse(r));