From eae27687458395a71c7fe9c4e82b3ed2608f0f9f Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Fri, 11 Jul 2025 17:51:00 -0500 Subject: prevent throwing when stopping --- src/slskd/Core/ConnectionWatchdog.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/slskd/Core/ConnectionWatchdog.cs b/src/slskd/Core/ConnectionWatchdog.cs index 2b4f6c21..e148024d 100644 --- a/src/slskd/Core/ConnectionWatchdog.cs +++ b/src/slskd/Core/ConnectionWatchdog.cs @@ -124,6 +124,7 @@ namespace slskd /// This should be called when the application is reasonably certain that the connection is connected. public virtual void Stop(bool abortReconnect = false) { + // stop the timer first to avoid having it start the connection process again when the cts is cancelled WatchdogTimer.Enabled = false; // note: the connect event fires before the connection logic is complete, so there is a chain of events @@ -132,7 +133,14 @@ namespace slskd // wants to abort the reconnect logic. if (abortReconnect) { - CancellationTokenSource?.Cancel(); + try + { + CancellationTokenSource?.Cancel(throwOnFirstException: false); + } + catch (Exception) + { + // noop. Cancel() can throw if registered callbacks throw, but we don't have any right now and we don't care anyway + } } } -- cgit v1.2.3