diff options
| author | JP Dillingham <jp@dillingham.me> | 2026-06-20 17:21:06 -0500 |
|---|---|---|
| committer | JP Dillingham <jp@dillingham.me> | 2026-06-20 17:27:42 -0500 |
| commit | 4ce36c42ab8d78ae5b9412e260d25736dbfa0f25 (patch) | |
| tree | 78536062426cc29ee0a7f46bb255c0ff321a940d /src/slskd/Telemetry/Metrics.cs | |
| parent | aae292484669b0618657d61f448f89bc168d27d4 (diff) | |
| download | slskd-4ce36c42ab8d78ae5b9412e260d25736dbfa0f25.tar.gz | |
fix deadlock on re-entrant update semaphore, tweak speed metric collection
Diffstat (limited to 'src/slskd/Telemetry/Metrics.cs')
| -rw-r--r-- | src/slskd/Telemetry/Metrics.cs | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/src/slskd/Telemetry/Metrics.cs b/src/slskd/Telemetry/Metrics.cs index 921941a9..822f6aeb 100644 --- a/src/slskd/Telemetry/Metrics.cs +++ b/src/slskd/Telemetry/Metrics.cs @@ -51,10 +51,15 @@ public static class Metrics /// <summary> /// Updates metrics under a mutex to prevent mismatches and under/overruns. /// </summary> + /// <remarks> + /// This method uses a <see cref="SemaphoreSlim"/> for synchronization and it is therefore safe to do async work + /// inside of <paramref name="work"/>, though it is discouraged for causing un-needed contention. + /// </remarks> /// <param name="work">Updates to execute.</param> - public static void Update(Action work) + /// <param name="cancellationToken">The token to monitor for cancellation requests.</param> + public static void Update(Action work, CancellationToken cancellationToken = default) { - SyncRoot.Wait(); + SyncRoot.Wait(cancellationToken); try { |
