diff options
| author | JP Dillingham <jp@dillingham.me> | 2025-07-11 17:51:00 -0500 |
|---|---|---|
| committer | JP Dillingham <jp@dillingham.me> | 2025-07-11 17:51:00 -0500 |
| commit | eae27687458395a71c7fe9c4e82b3ed2608f0f9f (patch) | |
| tree | bfa3f70da66124784ae3eee7956316c38e41f3d6 | |
| parent | 4667de5ef249bc3de93164c988c8721410907bc2 (diff) | |
| download | slskd-eae27687458395a71c7fe9c4e82b3ed2608f0f9f.tar.gz | |
prevent throwing when stopping
| -rw-r--r-- | src/slskd/Core/ConnectionWatchdog.cs | 10 |
1 files changed, 9 insertions, 1 deletions
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 /// <remarks>This should be called when the application is reasonably certain that the connection is connected.</remarks> 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 + } } } |
