perf(acl,grpc-data): #1053 alloc-free warm UNS ACL decisions; unresolvable configured refs back off; restart keeps the comms latch (decided)
U-8: a warm cached decision on a UNS node allocated 416-680 B/call ahead of the cache (live id-chain list, identifier split, LINQ, segment array, string.Join key, DataCallerIdentity). Now 0 B: the live chain is cached per folder instance (re-verified against the live ancestry every call), the generation hands out one segment array per path, the authorizer keys its resolved cache keys on that array, reference variables key on their own identifier (scope = its split), and the caller identity is built once per session identity. R-25: ConfiguredProjectedInterestOwner re-ran discovery for an unresolvable configured reference every 1 s sweep forever; a failed resolve now backs off 1 s doubling to 30 s (60 s unreachable: 61 discoveries -> 6). Publishing into the source hub only for sources with interest is DECLINED: that cache answers a new subscription's first snapshot and projected Reads. Restart comms latch (decided: keep): the nodes stay Bad across an operator Restart and the respawned incarnation must re-publish them; the stopped child's PostStop announcement already re-latches and cancels the old audit. Pinned by test. Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -137,10 +137,22 @@ public sealed class DataPlaneAuthoritySnapshot
|
||||
return false;
|
||||
}
|
||||
|
||||
unsSegments = path.Segments.Skip(1).ToArray();
|
||||
unsSegments = BelowRealm(path);
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <paramref name="path"/>'s segments below the realm, computed once per path instance (#1053 / review U-8). A
|
||||
/// generation's paths are immutable and these lookups run per ACL decision on every UNS node, so the
|
||||
/// <c>Skip(1).ToArray()</c> they used to do allocated on every warm cached decision. Callers treat the result as
|
||||
/// read-only; the same instance is returned for the life of the path, which also lets the authorizer key its own
|
||||
/// per-placement cache on it.
|
||||
/// </summary>
|
||||
private static IReadOnlyList<string> BelowRealm(NodeAclPath path) =>
|
||||
BelowRealmCache.GetValue(path, static p => p.Segments.Skip(1).ToArray());
|
||||
|
||||
private static readonly System.Runtime.CompilerServices.ConditionalWeakTable<NodeAclPath, string[]> BelowRealmCache = new();
|
||||
|
||||
/// <summary>
|
||||
/// <c>UNS folder id → (its ACL path, its folder-id chain)</c> for every UNS Area, Line and Equipment in the
|
||||
/// artifact this generation was built from (Gitea #808). Keyed <c>OrdinalIgnoreCase</c> (identifier rule).
|
||||
@@ -225,7 +237,7 @@ public sealed class DataPlaneAuthoritySnapshot
|
||||
if (!string.Equals(scope.IdChain[i], liveIdChain[i], StringComparison.OrdinalIgnoreCase)) return false;
|
||||
}
|
||||
|
||||
unsSegments = scope.Path.Segments.Skip(1).ToArray();
|
||||
unsSegments = BelowRealm(scope.Path);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -3391,7 +3391,7 @@ public sealed partial class OtOpcUaNodeManager : CustomNodeManager2, INodeManage
|
||||
// authority. Never a fallback to splitting the opaque id.
|
||||
var native = false;
|
||||
string? owner = null;
|
||||
List<string>? ownerChain = null;
|
||||
IReadOnlyList<string>? ownerChain = null;
|
||||
lock (Lock)
|
||||
{
|
||||
var key = MapKey(condition.NodeId);
|
||||
@@ -6396,8 +6396,14 @@ public sealed partial class OtOpcUaNodeManager : CustomNodeManager2, INodeManage
|
||||
/// </summary>
|
||||
/// <param name="folder">A live hierarchy folder.</param>
|
||||
/// <returns>The id chain.</returns>
|
||||
private List<string> LiveHierarchyChain(NodeState folder)
|
||||
private IReadOnlyList<string> LiveHierarchyChain(NodeState folder)
|
||||
{
|
||||
// #1053 / review U-8: the chain is cached on the folder INSTANCE but never trusted — every call re-walks the live
|
||||
// ancestry (alloc-free) and only reuses the cached array when every live id still matches it, so a re-parent, a
|
||||
// rebuild that re-mints an ancestor, or a torn-down ancestor rebuilds it exactly as before. The cached array is
|
||||
// also what the authorizer keys its per-placement cache on (one stable instance per placement).
|
||||
if (_hierarchyChains.TryGetValue(folder, out var cached) && LiveChainMatches(folder, cached)) return cached;
|
||||
|
||||
var chain = new List<string>(3);
|
||||
NodeState? current = folder;
|
||||
for (var depth = 0; current is not null && depth < MaxUnsAncestry; depth++, current = ParentOf(current))
|
||||
@@ -6407,9 +6413,32 @@ public sealed partial class OtOpcUaNodeManager : CustomNodeManager2, INodeManage
|
||||
}
|
||||
|
||||
chain.Reverse();
|
||||
return chain;
|
||||
var built = chain.ToArray();
|
||||
_hierarchyChains.AddOrUpdate(folder, built);
|
||||
return built;
|
||||
}
|
||||
|
||||
/// <summary>Whether <paramref name="folder"/>'s live ancestry is exactly <paramref name="cached"/> (no allocation).</summary>
|
||||
private bool LiveChainMatches(NodeState folder, string[] cached)
|
||||
{
|
||||
var i = cached.Length - 1;
|
||||
NodeState? current = folder;
|
||||
for (var depth = 0; current is not null && depth < MaxUnsAncestry; depth++, current = ParentOf(current))
|
||||
{
|
||||
if (LiveUnsFolderId(current) is not { } id || id.Contains('/')) break;
|
||||
if (i < 0 || !string.Equals(cached[i], id, StringComparison.Ordinal)) return false;
|
||||
i--;
|
||||
}
|
||||
|
||||
return i == -1;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The last live id chain computed per UNS folder instance (#1053 / review U-8). Weak, so a torn-down folder's entry
|
||||
/// goes with it; validated against the live ancestry on every read (<see cref="LiveChainMatches"/>).
|
||||
/// </summary>
|
||||
private readonly ConditionalWeakTable<NodeState, string[]> _hierarchyChains = new();
|
||||
|
||||
/// <summary>The <c>EquipmentId</c> the exact live <paramref name="condition"/> is bound to, or null. Call under <c>Lock</c>.</summary>
|
||||
private string? BoundScriptedOwner(RealmKey key, ConditionState condition) =>
|
||||
_scriptedAlarmOwners.TryGetValue(key, out var binding)
|
||||
@@ -6423,7 +6452,7 @@ public sealed partial class OtOpcUaNodeManager : CustomNodeManager2, INodeManage
|
||||
/// The live folder-id ancestry of the equipment folder a BOUND scripted condition hangs under (the #808 folder
|
||||
/// rule applied to the #797 owner), or null when unbound or no longer under that folder. Call under <c>Lock</c>.
|
||||
/// </summary>
|
||||
private List<string>? BoundScriptedOwnerChain(RealmKey key, ConditionState condition) =>
|
||||
private IReadOnlyList<string>? BoundScriptedOwnerChain(RealmKey key, ConditionState condition) =>
|
||||
BoundScriptedOwner(key, condition) is { } owner
|
||||
&& ParentOf(condition) is FolderState parent
|
||||
&& LiveUnsFolderId(parent) is { } parentId
|
||||
|
||||
@@ -159,8 +159,7 @@ public sealed class DataPlaneAuthorizer
|
||||
public bool AuthorizeProjectedAnchor(RoleCarryingUserIdentity? identity, NodeScope scope)
|
||||
{
|
||||
if (identity is null) return false;
|
||||
var caller = new DataCallerIdentity(identity.Principal, identity.ApiKeyId,
|
||||
identity.CredentialVersion, identity.CredentialExpiresUtc);
|
||||
var caller = identity.CallerIdentity;
|
||||
return _policy.AuthorizeLocal(caller, OpcUaOperation.Browse, scope);
|
||||
}
|
||||
|
||||
@@ -211,8 +210,7 @@ public sealed class DataPlaneAuthorizer
|
||||
if (operation is not (OpcUaOperation.Browse or OpcUaOperation.Read or OpcUaOperation.WriteOperate or OpcUaOperation.WriteTune
|
||||
or OpcUaOperation.WriteConfigure or OpcUaOperation.TransferSubscriptions or OpcUaOperation.HistoryRead))
|
||||
{ veto = DeniedResult; return true; }
|
||||
var caller = new DataCallerIdentity(identity.Principal, identity.ApiKeyId,
|
||||
identity.CredentialVersion, identity.CredentialExpiresUtc);
|
||||
var caller = identity.CallerIdentity;
|
||||
try
|
||||
{
|
||||
veto = _policy.AuthorizeMapped(caller, operation, resolved.View, resolved.Live.Serving,
|
||||
@@ -358,8 +356,7 @@ public sealed class DataPlaneAuthorizer
|
||||
if (identity?.ApiKeyId is not { Length: > 0 } keyId) return null;
|
||||
|
||||
var snapshot = _authority.Current;
|
||||
var caller = new DataCallerIdentity(identity.Principal, identity.ApiKeyId,
|
||||
identity.CredentialVersion, identity.CredentialExpiresUtc);
|
||||
var caller = identity.CallerIdentity;
|
||||
return !_policy.IsCallerUsable(caller, allowLegacyUnversionedKey: true)
|
||||
|| !ReferenceEquals(snapshot, _authority.Current)
|
||||
? DenyRevokedKey(operation, nodeId, identity.Principal, keyId, snapshot.GenerationId, cached: false)
|
||||
@@ -524,27 +521,45 @@ public sealed class DataPlaneAuthorizer
|
||||
/// <param name="identifier">The node's <c>s=</c> identifier (split only for the shapes that are paths).</param>
|
||||
/// <param name="snapshot">The generation in force.</param>
|
||||
/// <param name="subject">The live facts the node manager reported.</param>
|
||||
/// <param name="segments">The resolved path below the UNS realm root.</param>
|
||||
/// <param name="segments">
|
||||
/// The resolved path below the UNS realm root, or <see langword="null"/> when the scope is the identifier's own
|
||||
/// split (built by the caller only on a cache miss).
|
||||
/// </param>
|
||||
/// <param name="cacheKey">The decision-cache key naming that scope.</param>
|
||||
/// <param name="reason">Why placement failed.</param>
|
||||
/// <returns><see langword="true"/> when the subject is placed.</returns>
|
||||
private static bool TryPlaceUnsSubject(
|
||||
string identifier,
|
||||
DataPlaneAuthoritySnapshot snapshot,
|
||||
in UnsAclSubject subject,
|
||||
out IReadOnlyList<string> segments,
|
||||
out IReadOnlyList<string>? segments,
|
||||
out string cacheKey,
|
||||
out string reason)
|
||||
{
|
||||
// #1053 / review U-8: placement runs on EVERY decision, ahead of the cache, so a success here must not allocate.
|
||||
// A subject whose scope IS its identifier's own split (a reference variable, a reference-shaped unknown id) is
|
||||
// reported with segments == null and keyed on the identifier itself — Evaluate then builds that split only on a
|
||||
// cache MISS, and the key names the same scope a Path-kind lookup of the identifier would (BuildScope = split),
|
||||
// so the two can share an entry. Folder-placed subjects reuse the generation's cached segment array and the
|
||||
// per-placement keys below.
|
||||
IReadOnlyList<string> owner;
|
||||
bool owned;
|
||||
switch (subject.Kind)
|
||||
{
|
||||
case UnsAclSubjectKind.Unknown:
|
||||
{
|
||||
var split = identifier.Split('/', StringSplitOptions.RemoveEmptyEntries);
|
||||
segments = split.Length == ReferenceVariableSegments ? split : [UnknownNodeSegment];
|
||||
if (CountSegments(identifier) == ReferenceVariableSegments)
|
||||
{
|
||||
segments = null;
|
||||
cacheKey = identifier;
|
||||
}
|
||||
else
|
||||
{
|
||||
segments = UnknownSegments;
|
||||
cacheKey = UnknownCacheKey;
|
||||
}
|
||||
|
||||
reason = string.Empty;
|
||||
return true;
|
||||
}
|
||||
|
||||
case UnsAclSubjectKind.ReferenceVariable:
|
||||
{
|
||||
@@ -552,18 +567,18 @@ public sealed class DataPlaneAuthorizer
|
||||
// path is where THIS generation puts its equipment (plus one effective-name segment). An equipment
|
||||
// moved to another line, or an Area/Line/Equipment renamed, leaves the variable's id on the OLD names
|
||||
// until the address space re-points it; the old names' grants must not keep reading / writing it.
|
||||
var split = identifier.Split('/', StringSplitOptions.RemoveEmptyEntries);
|
||||
if (subject.FolderChain is not { Count: > 0 } equipmentChain
|
||||
|| !snapshot.TryGetUnsFolderSegments(equipmentChain[^1], equipmentChain, out var equipment)
|
||||
|| split.Length != equipment.Count + 1
|
||||
|| !split.Take(equipment.Count).SequenceEqual(equipment, StringComparer.Ordinal))
|
||||
|| !IsPlacementPlusOneName(identifier, equipment))
|
||||
{
|
||||
segments = [];
|
||||
segments = null;
|
||||
cacheKey = string.Empty;
|
||||
reason = $"the UNS reference variable's path does not match its equipment {subject.FolderChain?.LastOrDefault() ?? "(none)"}'s placement in generation {snapshot.GenerationId} (moved, renamed, or not yet re-pointed)";
|
||||
return false;
|
||||
}
|
||||
|
||||
segments = split;
|
||||
segments = null;
|
||||
cacheKey = identifier;
|
||||
reason = string.Empty;
|
||||
return true;
|
||||
}
|
||||
@@ -572,7 +587,8 @@ public sealed class DataPlaneAuthorizer
|
||||
if (subject.FolderChain is not { Count: > 0 } chain
|
||||
|| !snapshot.TryGetUnsFolderSegments(chain[^1], chain, out owner))
|
||||
{
|
||||
segments = [];
|
||||
segments = null;
|
||||
cacheKey = string.Empty;
|
||||
reason = $"the UNS folder {subject.FolderChain?.LastOrDefault() ?? "(none)"} is not placed as generation {snapshot.GenerationId} deploys it (unknown, moved, or not yet rebuilt)";
|
||||
return false;
|
||||
}
|
||||
@@ -584,7 +600,8 @@ public sealed class DataPlaneAuthorizer
|
||||
if (!TryPlaceScriptedCondition(
|
||||
snapshot, subject.AlarmId, subject.OwnerEquipmentId, subject.FolderChain, out owner, out reason))
|
||||
{
|
||||
segments = [];
|
||||
segments = null;
|
||||
cacheKey = string.Empty;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -592,16 +609,85 @@ public sealed class DataPlaneAuthorizer
|
||||
break;
|
||||
|
||||
default:
|
||||
segments = [];
|
||||
segments = null;
|
||||
cacheKey = string.Empty;
|
||||
reason = "unrecognised UNS subject";
|
||||
return false;
|
||||
}
|
||||
|
||||
segments = owned ? [.. owner, OwnedNodeSegment] : owner;
|
||||
var placement = PlacementOf(owner);
|
||||
segments = owned ? placement.OwnedSegments : owner;
|
||||
cacheKey = owned ? placement.OwnedKey : placement.Key;
|
||||
reason = string.Empty;
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>The scope an id no live node holds is placed at (see <see cref="UnknownNodeSegment"/>).</summary>
|
||||
private static readonly string[] UnknownSegments = [UnknownNodeSegment];
|
||||
|
||||
/// <summary>The decision-cache key of <see cref="UnknownSegments"/>.</summary>
|
||||
private static readonly string UnknownCacheKey = ResolvedScopeCacheKey(UnknownSegments);
|
||||
|
||||
/// <summary>
|
||||
/// The resolved scopes and cache keys of one placement (an owner path) — the folder itself and a node it owns.
|
||||
/// Built once per placement ARRAY: the generation hands out the same segment array for a path for its whole life
|
||||
/// (<c>DataPlaneAuthoritySnapshot.TryGetUnsFolderSegments</c> / <c>TryGetEquipmentUnsSegments</c>), so a weak
|
||||
/// table keyed on it is alloc-free on a warm hit and dies with the generation (#1053 / review U-8).
|
||||
/// </summary>
|
||||
private sealed class UnsPlacement
|
||||
{
|
||||
public UnsPlacement(IReadOnlyList<string> owner)
|
||||
{
|
||||
Key = ResolvedScopeCacheKey(owner);
|
||||
OwnedSegments = [.. owner, OwnedNodeSegment];
|
||||
OwnedKey = ResolvedScopeCacheKey(OwnedSegments);
|
||||
}
|
||||
|
||||
/// <summary>The folder's own cache key.</summary>
|
||||
public string Key { get; }
|
||||
|
||||
/// <summary>The scope of a node the folder owns: the owner path + <see cref="OwnedNodeSegment"/>.</summary>
|
||||
public string[] OwnedSegments { get; }
|
||||
|
||||
/// <summary>The cache key of <see cref="OwnedSegments"/>.</summary>
|
||||
public string OwnedKey { get; }
|
||||
}
|
||||
|
||||
private static readonly System.Runtime.CompilerServices.ConditionalWeakTable<IReadOnlyList<string>, UnsPlacement> Placements = new();
|
||||
|
||||
private static UnsPlacement PlacementOf(IReadOnlyList<string> owner) =>
|
||||
Placements.GetValue(owner, static o => new UnsPlacement(o));
|
||||
|
||||
/// <summary>How many non-empty <c>/</c>-separated segments <paramref name="identifier"/> has (the split's length).</summary>
|
||||
private static int CountSegments(string identifier)
|
||||
{
|
||||
var span = identifier.AsSpan();
|
||||
var count = 0;
|
||||
foreach (var range in span.Split('/'))
|
||||
if (!span[range].IsEmpty) count++;
|
||||
return count;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Whether <paramref name="identifier"/>'s non-empty segments are exactly <paramref name="placement"/> followed by
|
||||
/// one more (the effective name) — the split + <c>Take</c> + <c>SequenceEqual</c> it replaces, without allocating.
|
||||
/// </summary>
|
||||
private static bool IsPlacementPlusOneName(string identifier, IReadOnlyList<string> placement)
|
||||
{
|
||||
var span = identifier.AsSpan();
|
||||
var index = 0;
|
||||
foreach (var range in span.Split('/'))
|
||||
{
|
||||
var segment = span[range];
|
||||
if (segment.IsEmpty) continue;
|
||||
if (index > placement.Count) return false;
|
||||
if (index < placement.Count && !segment.SequenceEqual(placement[index].AsSpan())) return false;
|
||||
index++;
|
||||
}
|
||||
|
||||
return index == placement.Count + 1;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The decision-cache key for a node authorized at a RESOLVED scope rather than at its split identifier. It
|
||||
/// names the scope, not the node, because the cached grant walk depends only on the scope — and keying on the
|
||||
@@ -673,8 +759,7 @@ public sealed class DataPlaneAuthorizer
|
||||
// the next deploy — the generation never moves, so nothing would drop the entry.
|
||||
var now = _time.GetUtcNow().UtcDateTime;
|
||||
if (identity.ApiKeyId is { Length: > 0 } keyId
|
||||
&& (!_policy.IsCallerUsable(new DataCallerIdentity(identity.Principal, identity.ApiKeyId,
|
||||
identity.CredentialVersion, identity.CredentialExpiresUtc), allowLegacyUnversionedKey: true)
|
||||
&& (!_policy.IsCallerUsable(identity.CallerIdentity, allowLegacyUnversionedKey: true)
|
||||
|| !ReferenceEquals(snapshot, _authority.Current)))
|
||||
return DenyRevokedKey(operation, nodeId, identity.Principal, keyId, snapshot.GenerationId, cached);
|
||||
|
||||
@@ -709,11 +794,11 @@ public sealed class DataPlaneAuthorizer
|
||||
var subject = resolve(identifier);
|
||||
if (subject.Kind != UnsAclSubjectKind.Path)
|
||||
{
|
||||
if (!TryPlaceUnsSubject(identifier, snapshot, subject, out var placed, out var reason))
|
||||
if (!TryPlaceUnsSubject(identifier, snapshot, subject, out var placed, out var key, out var reason))
|
||||
return Deny(operation, nodeId, identity.Principal, reason, cached);
|
||||
|
||||
resolvedSegments = placed;
|
||||
cacheIdentifier = ResolvedScopeCacheKey(placed);
|
||||
cacheIdentifier = key;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -724,8 +809,7 @@ public sealed class DataPlaneAuthorizer
|
||||
// UserAuthorizationState. One Browse of a device folder asks this once per child.
|
||||
return memoized && ReferenceEquals(snapshot, _authority.Current)
|
||||
&& (identity.ApiKeyId is not { Length: > 0 } || _policy.IsCallerUsable(
|
||||
new DataCallerIdentity(identity.Principal, identity.ApiKeyId,
|
||||
identity.CredentialVersion, identity.CredentialExpiresUtc), allowLegacyUnversionedKey: true))
|
||||
identity.CallerIdentity, allowLegacyUnversionedKey: true))
|
||||
? null
|
||||
: DenyNoGrant(operation, nodeId, identity.Principal, snapshot.GenerationId, cached);
|
||||
}
|
||||
@@ -773,8 +857,7 @@ public sealed class DataPlaneAuthorizer
|
||||
NodeScope scope,
|
||||
DateTime now)
|
||||
{
|
||||
var caller = new DataCallerIdentity(identity.Principal, identity.ApiKeyId,
|
||||
identity.CredentialVersion, identity.CredentialExpiresUtc);
|
||||
var caller = identity.CallerIdentity;
|
||||
return _policy.AuthorizeLocal(caller, operation, scope, allowLegacyUnversionedKey: true);
|
||||
}
|
||||
|
||||
|
||||
@@ -97,4 +97,15 @@ public sealed class RoleCarryingUserIdentity : RoleBasedIdentity
|
||||
|
||||
/// <summary>Original credential expiry captured at activation.</summary>
|
||||
public DateTimeOffset? CredentialExpiresUtc { get; }
|
||||
|
||||
private ZB.MOM.WW.OtOpcUa.Core.Authorization.DataCallerIdentity? _callerIdentity;
|
||||
|
||||
/// <summary>
|
||||
/// The policy-side view of this identity (principal, key id, credential version + expiry), built once per identity
|
||||
/// rather than once per ACL decision (#1053 / review U-8: the cached decision path allocated it on every hit). Every
|
||||
/// input is immutable, so a benign race builds two equal instances.
|
||||
/// </summary>
|
||||
internal ZB.MOM.WW.OtOpcUa.Core.Authorization.DataCallerIdentity CallerIdentity =>
|
||||
_callerIdentity ??= new ZB.MOM.WW.OtOpcUa.Core.Authorization.DataCallerIdentity(
|
||||
Principal, ApiKeyId, CredentialVersion, CredentialExpiresUtc);
|
||||
}
|
||||
|
||||
+27
-1
@@ -17,7 +17,20 @@ public sealed class ConfiguredProjectedInterestOwner : IProjectedDependencyInter
|
||||
internal bool Desired = true, Queued, Running;
|
||||
internal IConfiguredProjectionLease? Lease;
|
||||
internal CancellationTokenSource? InFlight;
|
||||
// #1053 (R-25): consecutive failed resolves and when the sweep may try again. An explicit SetInterest re-queues
|
||||
// regardless; only the shared 1 s sweep honours the backoff.
|
||||
internal int Failures;
|
||||
internal DateTimeOffset NextAttemptUtc;
|
||||
}
|
||||
|
||||
/// <summary>First retry delay after a configured reference fails to resolve (#1053 / R-25).</summary>
|
||||
public static readonly TimeSpan MinRetryDelay = TimeSpan.FromSeconds(1);
|
||||
|
||||
/// <summary>Ceiling of that backoff: a reference whose origin comes back is resolved within this long.</summary>
|
||||
public static readonly TimeSpan MaxRetryDelay = TimeSpan.FromSeconds(30);
|
||||
|
||||
private static TimeSpan RetryDelay(int failures) =>
|
||||
TimeSpan.FromTicks(Math.Min(MaxRetryDelay.Ticks, MinRetryDelay.Ticks * (1L << Math.Min(Math.Max(failures, 1) - 1, 20))));
|
||||
private readonly object _sync = new();
|
||||
private readonly Dictionary<string, Entry> _entries = new(StringComparer.Ordinal);
|
||||
private readonly Queue<Entry> _ready = new();
|
||||
@@ -106,6 +119,13 @@ public sealed class ConfiguredProjectedInterestOwner : IProjectedDependencyInter
|
||||
lock (_sync)
|
||||
{
|
||||
entry.Lease = acquired; entry.Running = false;
|
||||
if (acquired is not null) entry.Failures = 0;
|
||||
else if (operation is not null && !canceled && entry.Desired)
|
||||
{
|
||||
// #1053 (R-25): an unresolvable configured reference used to be rediscovered on every 1 s sweep forever.
|
||||
entry.Failures++;
|
||||
entry.NextAttemptUtc = _clock.GetUtcNow() + RetryDelay(entry.Failures);
|
||||
}
|
||||
if (!entry.Desired || _disposed)
|
||||
{
|
||||
if (entry.Lease is not null) Queue(entry);
|
||||
@@ -120,7 +140,13 @@ public sealed class ConfiguredProjectedInterestOwner : IProjectedDependencyInter
|
||||
{
|
||||
using var timer = new PeriodicTimer(TimeSpan.FromSeconds(1), _clock);
|
||||
while (await timer.WaitForNextTickAsync(_stop.Token).ConfigureAwait(false))
|
||||
lock (_sync) foreach (var entry in _entries.Values) if (entry.Desired) Queue(entry);
|
||||
{
|
||||
var now = _clock.GetUtcNow();
|
||||
// A held lease is re-checked every sweep (cheap: IsValid); an entry without one waits out its backoff.
|
||||
lock (_sync)
|
||||
foreach (var entry in _entries.Values)
|
||||
if (entry.Desired && (entry.Lease is not null || now >= entry.NextAttemptUtc)) Queue(entry);
|
||||
}
|
||||
}
|
||||
catch (OperationCanceledException) { }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user