Commit b95b218
committed
fix(opcua,#386): per-MI active flag for event MI removal (Copilot review)
Two correctness fixes from Copilot's review of PR #387 in the same
concurrency cluster:
[Blocker] ``remove_event_monitored_item`` was bumping the global
``generation`` counter to invalidate in-flight callbacks for the MI
being removed. That works for the removed MI but ALSO trips the
trampoline staleness check for every peer monitored item registered
against the same subscription, silently dropping their callbacks even
though their server-side MIs are still live. Replace with a per-context
``std::atomic<bool> active`` flag flipped to false before the unique_ptr
is moved out; the trampoline reads it (acquire) ahead of dispatch and
bails for that MI only. Global ``generation`` stays reserved for full
disconnect / ``remove_subscriptions``.
[Defensive] ``setup_event_subscriptions`` was capturing
``const auto & cfg`` from a range-for by reference. Per current C++
semantics the captured reference resolves to the underlying vector
element (not the local reference variable), so the closure stays valid
- the integration test fires three distinct alarms and gets three
distinct fault_codes, confirming each callback uses its own cfg. But
value capture is unambiguous and matches the review feedback.
``AlarmEventConfig`` is a small struct of strings, so the copy is
cheap.
New test ``RemoveEventMonitoredItemUnknownIdDoesNotBumpGeneration``
locks the contract: peer MI staleness must not be triggered by an
unknown-ID single removal.
Local verify: 27/27 test_opcua_client + 27/27 test_alarm_state_machine.1 parent 0c11ac9 commit b95b218
3 files changed
Lines changed: 58 additions & 8 deletions
File tree
- src/ros2_medkit_plugins/ros2_medkit_opcua
- src
- test
Lines changed: 35 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
41 | | - | |
42 | | - | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
43 | 52 | | |
44 | 53 | | |
45 | 54 | | |
| 55 | + | |
46 | 56 | | |
47 | 57 | | |
48 | 58 | | |
| |||
602 | 612 | | |
603 | 613 | | |
604 | 614 | | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
605 | 622 | | |
606 | 623 | | |
607 | 624 | | |
| |||
743 | 760 | | |
744 | 761 | | |
745 | 762 | | |
| 763 | + | |
| 764 | + | |
| 765 | + | |
| 766 | + | |
| 767 | + | |
| 768 | + | |
| 769 | + | |
| 770 | + | |
| 771 | + | |
| 772 | + | |
| 773 | + | |
| 774 | + | |
| 775 | + | |
| 776 | + | |
| 777 | + | |
| 778 | + | |
746 | 779 | | |
747 | 780 | | |
748 | 781 | | |
749 | 782 | | |
750 | | - | |
751 | | - | |
752 | | - | |
753 | | - | |
754 | 783 | | |
755 | 784 | | |
756 | 785 | | |
| |||
Lines changed: 10 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
232 | 232 | | |
233 | 233 | | |
234 | 234 | | |
235 | | - | |
236 | | - | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
237 | 245 | | |
238 | 246 | | |
239 | 247 | | |
| |||
Lines changed: 13 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
131 | 131 | | |
132 | 132 | | |
133 | 133 | | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
134 | 147 | | |
135 | 148 | | |
136 | 149 | | |
| |||
0 commit comments