fix(controlplane): evict retired mesh channels and refresh PSKs off the request path
- MeshGrpcCommandDialer.RetainOnly (IMeshCommandDialer, default no-op): CentralCommunicationActor hands the dialer the current endpoint set on every contact refresh, so a renamed host or moved port releases its cached GrpcChannel and idle HTTP/2 connection instead of living for the process (R03:1.3). - IMeshPskProvider.RefreshAsync (default = the old InvalidateAll): MeshPskProvider pre-resolves every known cluster's key concurrently, bounded like the sync path, and swaps an immutable snapshot in atomically; a failed read keeps that cluster's previous key. The actor calls it from ContactsLoaded (after SetKnownClusters, off-actor via PipeTo) instead of InvalidateAll, so the first ack per cluster per ContactRefreshSeconds no longer blocks a gRPC thread on a 3 s-bounded store read or gets denied past the bound (R03:3.4). Refs #733 Claude-Session: https://claude.ai/code/session_01Ub9hGmYLQvn9XETzw7CMsT
This commit is contained in:
+56
-1
@@ -201,6 +201,9 @@ public sealed class CentralCommunicationActor : ReceiveActor, IWithTimers
|
||||
LoadContactsFromDb();
|
||||
});
|
||||
Receive<ContactsLoaded>(HandleContactsLoaded);
|
||||
Receive<PskRefreshed>(msg => _log.Debug("Mesh PSK refresh completed for {Count} cluster(s)", msg.ClusterCount));
|
||||
Receive<PskRefreshFailed>(msg => _log.Warning(msg.Error,
|
||||
"Mesh PSK refresh failed; previously resolved keys stay in service until the next refresh"));
|
||||
Receive<CommandDispatched>(HandleCommandDispatched);
|
||||
|
||||
// A faulted LoadContactsFromDb task is piped here as a Status.Failure. Without this handler
|
||||
@@ -710,6 +713,20 @@ public sealed class CentralCommunicationActor : ReceiveActor, IWithTimers
|
||||
|
||||
_targets = msg.Targets;
|
||||
|
||||
// R03:1.3 — release the channels of endpoints that left the dispatch set (host renamed, port
|
||||
// moved). Only the resolved dialer is asked; nothing is resolved just to prune it.
|
||||
if (_dialer is { } dialer)
|
||||
{
|
||||
try
|
||||
{
|
||||
dialer.RetainOnly(_targets.Select(t => t.Endpoint).ToHashSet(StringComparer.Ordinal));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_log.Warning(ex, "Mesh dialer failed to release channels for retired endpoints; they stay cached until the next refresh");
|
||||
}
|
||||
}
|
||||
|
||||
if (_targets.Count == 0)
|
||||
{
|
||||
_log.Warning(
|
||||
@@ -780,7 +797,37 @@ public sealed class CentralCommunicationActor : ReceiveActor, IWithTimers
|
||||
}
|
||||
|
||||
pskProvider.SetKnownClusters(msg.ClusterIds);
|
||||
pskProvider.InvalidateAll();
|
||||
|
||||
// R03:3.4 — refresh the per-cluster keys OFF the request path and swap them in atomically,
|
||||
// instead of dropping the cache and making the first ack per cluster re-read the store on a
|
||||
// gRPC thread. A provider that does not pre-resolve (the interface default, and every fake)
|
||||
// still drops its cache here, synchronously, exactly as before.
|
||||
CancellationToken ct;
|
||||
try
|
||||
{
|
||||
ct = _lifecycle.Token;
|
||||
}
|
||||
catch (ObjectDisposedException)
|
||||
{
|
||||
return; // Stopping.
|
||||
}
|
||||
var self = Self;
|
||||
Task refresh;
|
||||
try
|
||||
{
|
||||
refresh = pskProvider.RefreshAsync(msg.ClusterIds, ct);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_log.Warning(ex, "Mesh PSK refresh threw synchronously; cached keys are unchanged until the next refresh");
|
||||
refresh = Task.CompletedTask;
|
||||
}
|
||||
if (!refresh.IsCompletedSuccessfully)
|
||||
{
|
||||
refresh.PipeTo(self,
|
||||
success: () => new PskRefreshed(msg.ClusterIds.Count),
|
||||
failure: ex => new PskRefreshFailed(ex));
|
||||
}
|
||||
|
||||
if (!_gatePublished)
|
||||
{
|
||||
@@ -795,6 +842,14 @@ public sealed class CentralCommunicationActor : ReceiveActor, IWithTimers
|
||||
/// <summary>Internal tick asking for a contact-point refresh.</summary>
|
||||
public sealed record RefreshContacts;
|
||||
|
||||
/// <summary>The asynchronous PSK refresh (R03:3.4) completed.</summary>
|
||||
/// <param name="ClusterCount">How many clusters were refreshed.</param>
|
||||
public sealed record PskRefreshed(int ClusterCount);
|
||||
|
||||
/// <summary>The asynchronous PSK refresh (R03:3.4) threw; the previous keys stay in service.</summary>
|
||||
/// <param name="Error">The failure.</param>
|
||||
public sealed record PskRefreshFailed(Exception Error);
|
||||
|
||||
/// <summary>Result of a contact-point load, piped back from the DB read.</summary>
|
||||
/// <param name="Targets">
|
||||
/// The gRPC dispatch set: one entry per enabled, non-maintenance row that carries a
|
||||
|
||||
Reference in New Issue
Block a user