fix(grpc-data): A3 r2 — a released marked EventFieldList never re-enters the SDK's process-wide pool
SDK 2.0.1 pools EventFieldList (PooledEncodeableType); SentMessageQueue Reuse()s every list of an acknowledged message and the base ReuseCore returns it, whatever its runtime type, to the shared stock pool. A recycled ProjectedEventFieldList was then rented by any server's GetEventFields (an unrelated session's RefreshStart/RefreshEnd or local event) still carrying an imported condition's marker, and ProjectedNotificationRewriter dropped it when that marker's gate denied. Root cause of the intermittent OI ConditionRefresh failures (#854/#855 classes). Mirrors ProjectedSdkNotification on the data path: override ReuseCore, clear the marker, never return to the pool; a released (marker-less) list fails closed.
This commit is contained in:
@@ -461,11 +461,30 @@ internal sealed record ProjectedEventMarker(object? Identity, NodeId ConditionId
|
||||
/// <c>ProjectedNotificationRewriter</c> sees this instance on every Publish and Republish and drops it when the re-check
|
||||
/// fails.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// A3 review round 2 (root cause of the OI refresh failures): SDK 2.0.1 POOLS <see cref="EventFieldList"/> process-wide
|
||||
/// (<c>EventFieldListActivator : PooledEncodeableType</c>). <c>SentMessageQueue</c> calls <c>Reuse()</c> on every list of an
|
||||
/// acknowledged/evicted message, and the base <c>ReuseCore</c> returns the instance — whatever its runtime type — to the
|
||||
/// shared stock pool, from which ANY server's <c>MonitoredItem.GetEventFields</c> rents its next list. A recycled
|
||||
/// instance of this subclass therefore became some unrelated session's RefreshStart/RefreshEnd or local condition event,
|
||||
/// still carrying THIS marker: the rewriter judged it by another condition's (possibly revoked) gate and dropped it.
|
||||
/// Like <c>ProjectedSdkNotification</c> on the data path, this subclass stays out of the stock pool.
|
||||
/// </remarks>
|
||||
internal sealed class ProjectedEventFieldList(ProjectedEventMarker marker) : EventFieldList
|
||||
{
|
||||
internal static long s_unservable, s_droppedOnPublish, s_droppedUnmarked, s_keptUnmarked;
|
||||
|
||||
public ProjectedEventMarker Marker { get; } = marker;
|
||||
/// <summary>The captured authority; null once the SDK has released the list (it is never published again).</summary>
|
||||
public ProjectedEventMarker? Marker { get; private set; } = marker;
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void ReuseCore()
|
||||
{
|
||||
// ACK, eviction and message disposal reach this through IPooledEncodeable.Reuse: reset, drop the marker (and with it
|
||||
// the closure over the condition and identity), and let the GC have it — never the shared EventFieldList pool.
|
||||
Marker = null;
|
||||
ResetForReuse();
|
||||
}
|
||||
|
||||
/// <summary>Imported events an item could not receive through the marked path (fail closed).</summary>
|
||||
internal static long Unservable => Interlocked.Read(ref s_unservable);
|
||||
|
||||
@@ -938,7 +938,7 @@ internal static class ProjectedNotificationRewriter
|
||||
{
|
||||
if (list is ProjectedEventFieldList marked)
|
||||
{
|
||||
if (marked.Marker.Permits()) kept.Add(list);
|
||||
if (marked.Marker?.Permits() == true) kept.Add(list); // a released list (no marker) fails closed
|
||||
else Interlocked.Increment(ref ProjectedEventFieldList.s_droppedOnPublish);
|
||||
continue;
|
||||
}
|
||||
|
||||
+33
@@ -116,6 +116,39 @@ public sealed class ImportedConditionClassifierTests : IAsyncDisposable
|
||||
ReferenceEquals(ProjectedNotificationRewriter.Project(plain, republish: false, null), plain).ShouldBeTrue();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A3 review round 2 (root cause of the intermittent OI ConditionRefresh failures): SDK 2.0.1 pools EventFieldList
|
||||
/// process-wide, and <c>SentMessageQueue</c> calls <c>Reuse()</c> on every list of an acknowledged message. A marked
|
||||
/// list that went back to the stock pool was rented by an unrelated server/session's <c>GetEventFields</c> (its
|
||||
/// RefreshStart/RefreshEnd), carrying a revoked marker, and the rewriter dropped it. A released marked list must never
|
||||
/// be rentable, and must not keep its marker (closure over condition + identity) alive.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void A_released_marked_event_list_never_returns_to_the_SDK_pool_so_no_other_session_rents_its_marker()
|
||||
{
|
||||
var marked = new ProjectedEventFieldList(new ProjectedEventMarker(null, new NodeId("c", 9), 1, () => false)) { ClientHandle = 77 };
|
||||
((IPooledEncodeable)marked).Reuse(); // exactly what SentMessageQueue.ReuseNotificationPayloads does on ACK / eviction
|
||||
marked.Marker.ShouldBeNull("a released list holds no authority (and keeps no closure alive)");
|
||||
|
||||
// Drain more than the pool can hold: had the marked instance been returned, it would come out here.
|
||||
var rented = new List<EventFieldList>();
|
||||
try
|
||||
{
|
||||
for (var i = 0; i < PooledEncodeableType<EventFieldList>.DefaultMaximumRetained + 64; i++)
|
||||
rented.Add((EventFieldList)EventFieldListActivator.Instance.CreateInstance());
|
||||
rented.ShouldNotContain(l => l is ProjectedEventFieldList, "a stock list rented for any event is never a marked one");
|
||||
}
|
||||
finally
|
||||
{
|
||||
foreach (var l in rented) ((IPooledEncodeable)l).Reuse();
|
||||
}
|
||||
|
||||
// A released marked list that somehow reached the rewriter fails closed (never judged by a stale marker).
|
||||
var message = new NotificationMessage { SequenceNumber = 10,
|
||||
NotificationData = [new ExtensionObject(new EventNotificationList { Events = [marked] })] };
|
||||
ProjectedNotificationRewriter.Project(message, republish: false, null).NotificationData.Count.ShouldBe(0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void S2_a_cached_positive_verdict_is_re_proved_past_the_credential_expiry_and_past_the_positive_TTL()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user