fix(twincat): retract the fresh ADS notification when unsubscribe raced the replay (05/STAB-17)

This commit is contained in:
Joseph Doherty
2026-07-13 12:39:39 -04:00
parent de29759643
commit 082ee99b6b
4 changed files with 66 additions and 3 deletions
@@ -878,6 +878,15 @@ public sealed class TwinCATDriver : IDriver, IReadable, IWritable, ITagDiscovery
_options.NotificationMaxDelayMs, reg.OnChange, ct).ConfigureAwait(false);
var old = reg.SwapHandle(newHandle);
try { old?.Dispose(); } catch { /* dead handle from the disposed client */ }
// 05/STAB-17: an UnsubscribeAsync (gate-free) can race this replay — if it removed the
// registration between the intents snapshot and this swap, the fresh handle is
// ownerless. Retract it immediately so the ADS notification isn't leaked live.
if (!device.NativeRegistrations.ContainsKey(reg.Id))
{
var orphan = reg.MarkHandleDead();
try { orphan?.Dispose(); } catch { /* best-effort */ }
continue;
}
replayed++;
}
catch (Exception ex)