fix(communication): evict idle SiteStreamGrpcClientFactory (site, endpoint) clients (ScadaBridge#67)

Each cached client records when it was last handed out; a periodic sweep (half of the new
CommunicationOptions.GrpcClientIdleTtl, default 30 min, 0 disables) disposes and removes entries
unused for the TTL that have no live subscription (SiteStreamGrpcClient.ActiveSubscriptionCount).
Lookup and the sweep's check-and-remove share one lock so a handed-out client is never disposed
under its caller; an evicted client is re-created on next GetOrCreate.
This commit is contained in:
Joseph Doherty
2026-11-09 12:07:28 -05:00
parent e1734675e9
commit e2b15bd520
6 changed files with 300 additions and 14 deletions
@@ -131,6 +131,12 @@ public class SiteStreamGrpcClient : IAsyncDisposable, IDisposable
ConnectedHeaderTimeout = options.ConnectedHeaderTimeout;
}
/// <summary>
/// Number of live subscriptions currently registered on this client. The owning
/// <see cref="SiteStreamGrpcClientFactory"/> never evicts a client while this is non-zero.
/// </summary>
public virtual int ActiveSubscriptionCount => _subscriptions.Count;
/// <summary>
/// Registers a CancellationTokenSource for a correlation ID. Test-only.
/// </summary>