Repository navigation
Server: stop per-node subscriptions to DefaultPermissionsChanged - #5211
Conversation
…ter (N14) Every MonitoredNode2 subscribed to the server-wide IConfigurationNodeManager.DefaultPermissionsChanged event on its first item and unsubscribed on its last, and every SamplingGroup did the same on startup. Each += / -= rebuilds the multicast invocation list, an array as long as all subscribers, so adding or removing a monitored item cost O(monitored nodes on the server) and a reload of a manager with many monitored nodes was quadratic. DefaultPermissionsVersion now subscribes once per configuration node manager and counts the notifications. Monitored nodes fold the counter into the generation that stamps their cached data-change, event and event-restriction verdicts; sampling groups fold it into their permission epoch. A notification still invalidates every verdict before its next use, as before, but adding and removing items no longer touches the event. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Code coverage✅ Coverage gate passed.
Coverage is above the recorded baseline - consider ratcheting Thresholds live in |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #5211 +/- ##
==========================================
- Coverage 83.87% 83.85% -0.02%
==========================================
Files 3878 3879 +1
Lines 575722 575722
Branches 99274 99270 -4
==========================================
- Hits 482893 482779 -114
- Misses 60129 60227 +98
- Partials 32700 32716 +16
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
A concurrent first caller could see the subscribed flag before the handler was attached and stamp a verdict with a counter that could still miss a notification. Subscribe under a lock and publish the flag after the handler is attached; a regression test gates the event add accessor with two concurrent callers. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
🔵 Needs a closer look
The reported full-load concurrency test failure, despite isolated passes, requires human confirmation of final CI results and its disposition because the change affects shared authorization-cache invalidation.
No open issues 🎉
1 resolved since last review
Review effort: Balanced
|
On the local failure of 🤖 Addressed by Claude Code |

Part of the NodeManager lifetime follow-ups (#4931), item N14.
Problem
Every
MonitoredNode2subscribed to the server-wideIConfigurationNodeManager.DefaultPermissionsChangedevent when its first item was added, and unsubscribed when its last item was removed. EverySamplingGroupdid the same on startup and shutdown. Each+=/-=rebuilds the multicast invocation list, an array as long as all the subscribers. Adding or removing a monitored item therefore cost O(monitored nodes on the server), and reloading a manager with many monitored nodes was quadratic. The #5168 baseline (f4-sampled-churn: 20 managers × 500 variables, one reload per second) attributes half of the reload allocation to thatobject[]inMonitoredNode2.Remove.Change
DefaultPermissionsVersion: one subscription per configuration node manager, which counts its notifications. It is held in aConditionalWeakTablekeyed on the manager and subscribes exactly once. Each counter starts in its own 2^32 range, so a verdict stamped against a replaced configuration manager never matches.MonitoredNode2folds the counter into the generation that stamps its cached data-change verdicts, event verdicts and event-restriction verdicts (PermissionGeneration).Add,RemoveandDisposeno longer touch the event.SamplingGroup.PermissionEpochfolds in the same counter instead of a subscription per group. A group also no longer misses a change that arrives betweenShutdownand the nextStartup.Semantics are unchanged: every notification still invalidates every cached verdict before it is next used. The counter is captured before validation and compared again before the verdict is stored, the same way
m_permissionGenerationalready worked. A change that never raises the event is handled as before: the registry and namespace-default cache stamps (NamespaceDefaultPermissionReader.Generation, static-defaults checks) are untouched.I chose this over a per-namespace counter in the #5183 cache. The event fires for exactly the changes it covers today, including defaults behind read callbacks, namespaces without cache entries and custom
IConfigurationNodeManagerimplementations. Narrowing invalidation to a single namespace would be a separate optimisation, and today's event invalidates every namespace too.Measurements
Micro-measure (new test
AddAndRemoveItemAllocationIsIndependentOfMonitoredNodeCount, net10.0): bytes allocated per add+remove of one item on one node.The test fails on master: 130,753 B more at 5,010 nodes.
f4-sampled-churnA/B (lifecycle-reload --load 0 --readers 0 --lc-managers 20 --lc-vars 500 --lc-sampling 100 --lc-interval 1000 --lc-remove-every 0 --duration 15 --warmup 8; the control line is the same command with--lc-interval 0). Setup: master567363fadagainst this branch, Release net10.0, Server GC, bins atC:\un14mandC:\un14b, 4 rounds with the first side alternating, foreign load 0 cores in every run, 16 reloads per run with 0 failures on both sides. Each cell is the median [min..max].The net figures subtract the control median and divide by 16 reloads. The #5168 baseline recorded about 54 MB per reload on master.
Tests
MonitoredNode2Tests: the dispose test now asserts that a node never subscribes. A new test checks that three nodes share one subscription, that cached verdicts are reused, and that one notification re-validates every node.InFlightDataPermissionCannotReviveInvalidatedGrantAsync(defaultsChanged: true)still covers the in-flight race.Opc.Ua.Server.Tests, net10.0, full run: 12,539 passed, 9 failed. Eight failures are the symlink tests, which need a privilege this machine lacks.PreparedBatchImmediateCutoffPreservesCapturedNativeReadAsync(True)failed under full load and passed 3 times out of 3 when run alone.🤖 Generated with Claude Code