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:
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user