fix(grpc-data): #926 review r2 - deferred alarms and marks replay in arrival order; stale-record guard; F5 count on withdraw
- OpcUaPublishActor: deferred alarm states, qualities and condition marks replay as one arrival-ordered list (a withdrawal followed by a re-establishing transition ended unknown); marks held per (realm, condition) so withdrawals are bounded by the condition set - OpcUaClientDriver: signal/withdraw re-check the registration under _alarmStateLock; removals take the lock - DriverHostActor: a withdrawal under a raised F5 diagnostic updates its count - docs: Unsignalable/backstop residual; AlarmInitialStatePublished must stay in-process - tests: arrival-order replay (+ mirror), backstop positive control, F5 count
This commit is contained in:
@@ -1374,7 +1374,10 @@ public sealed class OpcUaClientDriver : IDriver, ITagDiscovery, IReadable, IWrit
|
||||
|
||||
foreach (var key in _alarmSubscriptions.Keys)
|
||||
{
|
||||
if (!_alarmSubscriptions.TryRemove(key, out var ras)) continue;
|
||||
RemoteAlarmSubscription? ras;
|
||||
// #926 review r2: removed under the emission lock, so no signal / withdrawal is mid-flight for it.
|
||||
lock (_alarmStateLock)
|
||||
if (!_alarmSubscriptions.TryRemove(key, out ras)) continue;
|
||||
try { ras.EventItem.Notification -= ras.Handler; }
|
||||
catch { /* best-effort */ }
|
||||
if (sessionAlive) deletes.Add(DeleteSubscriptionBestEffortAsync(ras.Subscription, budget.Token));
|
||||
@@ -2646,7 +2649,10 @@ public sealed class OpcUaClientDriver : IDriver, ITagDiscovery, IReadable, IWrit
|
||||
public async Task UnsubscribeAlarmsAsync(IAlarmSubscriptionHandle handle, CancellationToken cancellationToken)
|
||||
{
|
||||
if (handle is not OpcUaAlarmSubscriptionHandle h) return;
|
||||
if (!_alarmSubscriptions.TryRemove(h.Id, out var rs)) return;
|
||||
RemoteAlarmSubscription? rs;
|
||||
// #926 review r2: removed under the emission lock, so no signal / withdrawal is mid-flight for it.
|
||||
lock (_alarmStateLock)
|
||||
if (!_alarmSubscriptions.TryRemove(h.Id, out rs)) return;
|
||||
var emptied = NoteSubscriptionDeleted();
|
||||
|
||||
await _subscriptionGate.WaitAsync(cancellationToken).ConfigureAwait(false);
|
||||
@@ -2992,6 +2998,9 @@ public sealed class OpcUaClientDriver : IDriver, ITagDiscovery, IReadable, IWrit
|
||||
b.Open = false;
|
||||
if (opened && b.LossSinceStart is null)
|
||||
{
|
||||
// #926 review r2: re-checked UNDER the lock (the lookup above ran outside it, and an unsubscribe
|
||||
// removes the record under this lock): a released subscription never signals.
|
||||
if (!IsRegisteredLocked(ras)) return;
|
||||
// grpc-data A1 (F1): the refresh replay this subscription requested is complete, lossless, and every
|
||||
// refreshed event before it was routed (sequential publishing, G2). Under the emission lock, so the
|
||||
// signal is ordered behind every emission. Covers the subscription's alarm RawPaths. Ends the
|
||||
@@ -3045,6 +3054,9 @@ public sealed class OpcUaClientDriver : IDriver, ITagDiscovery, IReadable, IWrit
|
||||
{
|
||||
if (!ras.Bracket.Signalled) return;
|
||||
ras.Bracket.Signalled = false;
|
||||
// #926 review r2: a stale record (unsubscribed after the caller's lookup, still Signalled) must not withdraw
|
||||
// refs that may now belong to a NEW subscription. Checked under the lock the unsubscribe removes it under.
|
||||
if (!IsRegisteredLocked(ras)) return;
|
||||
_logger.LogWarning(
|
||||
"OpcUaClientDriver '{DriverInstanceId}': alarm subscription {SubscriptionId} lost events after its conditions " +
|
||||
"were declared known ({Reason}); withdrawing 'known' until a lossless ConditionRefresh.",
|
||||
@@ -3052,6 +3064,13 @@ public sealed class OpcUaClientDriver : IDriver, ITagDiscovery, IReadable, IWrit
|
||||
RaiseInitialAlarmState(ras.AlarmRefs, unsignalable: false, withdrawn: true);
|
||||
}
|
||||
|
||||
/// <summary>#926 review r2: <paramref name="ras"/> is still the registered subscription for its handle. Caller holds
|
||||
/// <c>_alarmStateLock</c>; removals take it too, so the answer holds for the rest of the critical section.</summary>
|
||||
/// <param name="ras">The alarm subscription record.</param>
|
||||
/// <returns>Whether it is the live registration.</returns>
|
||||
private bool IsRegisteredLocked(RemoteAlarmSubscription ras) =>
|
||||
_alarmSubscriptions.TryGetValue(ras.Handle.Id, out var current) && ReferenceEquals(current, ras);
|
||||
|
||||
/// <summary>
|
||||
/// #926: the publish-sequence check of alarm subscription <paramref name="handle"/>. The alarm subscription holds
|
||||
/// exactly one (event) monitored item, so every data-bearing notification message it receives carries its
|
||||
|
||||
Reference in New Issue
Block a user