Skip to content

fix(opcua): send the ConditionId clause an empty BrowsePath, not a null one - #777

Closed
mfaferek93 wants to merge 2 commits into
mainfrom
fix/opcua-condition-id-empty-browse-path
Closed

mfaferek93 wants to merge 2 commits into
mainfrom
fix/opcua-condition-id-empty-browse-path

Conversation

@mfaferek93

@mfaferek93 mfaferek93 commented Nov 8, 2026 •

Copy link
Copy Markdown
Collaborator

What

The event filter the OPC UA plugin sends with every Alarms & Conditions subscription has a ConditionId select clause with no BrowsePath (ConditionType, AttributeId=NodeId). The plugin left browsePath as a NULL pointer, which open62541 encodes as a null array (length -1).

A Siemens S7-1500 answers a null BrowsePath with a null ConditionId. The plugin drops every event with a null ConditionId as a non-condition event, so no native Program_Alarm ever became a fault:

OPC-UA non-condition event on configured alarm source 'ns=0;i=2253' (fault_code 'PLC_ALARM') carries a null ConditionId and was dropped

The clause now carries an empty array (length 0).

Changes

  • make_event_filter sets browsePath to UA_EMPTY_ARRAY_SENTINEL when the path is empty. It moves to a detail namespace so a test can call it.
  • New test EventFilterTest.ConditionIdClauseSendsEmptyNotNullBrowsePath: encodes the clause, decodes it and checks it decodes as an empty array, not a null one.

Testing

  • The new test fails on main (browsePath decodes as NULL) and passes with the fix.
  • colcon test --packages-select ros2_medkit_opcua: passes (Release), including the test_alarm_server integration tests.
  • The first CI run had sanitizer-tsan red: a data race in the test DiscoverEndpoint.TheScanIsAnnouncedBeforeTheSweepRuns, a test already on main. Its scan lambda runs on the sweep's worker threads, and two first probes could both see the shared string empty and assign it at once. The race only shows when two probes overlap, so it is rare. A short sleep between the check and the assignment makes it show on every run. The second commit puts a mutex around the check and the assignment. With the same sleep, 10 of 10 runs are clean. Without the sleep, ctest -LE linter for ros2_medkit_opcua in a TSan build (RelWithDebInfo, the CI suppressions, timeouts x3) passes 21/21 with no race report.
  • On a CPU 1505SP F (FW V21.9): the plugin connects, the event monitored item with the new filter is accepted (server diagnostics show the item and the ConditionRefresh notifications), and polling is unchanged.

…ll one

The ConditionId select clause has no BrowsePath. It went out as a null
array (length -1), and a Siemens S7-1500 answers that with a null
ConditionId, so every native alarm was dropped as a non-condition event.
It now goes out as an empty array (length 0).
Copilot AI balanced review requested due to automatic review settings November 8, 2026 22:29

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are identified for the change to send empty rather than null ConditionId browse paths.

No open issues 🎉

What changed in this PR

Fixes OPC UA alarm subscriptions so the ConditionId clause sends an empty BrowsePath rather than a null array, addressing Siemens S7-1500 alarms being dropped because of null ConditionIds.

Changes:

  • Uses UA_EMPTY_ARRAY_SENTINEL for empty event-filter browse paths.
  • Exposes the filter builder in the detail namespace for testing.
  • Adds a binary encode/decode regression test that distinguishes empty arrays from null arrays.
File Description
src/​ros2_medkit_plugins/​ros2_medkit_opcua/​test/​test_opcua_client.cpp Verifies the ConditionId BrowsePath remains empty, not null, after serialization.
src/​ros2_medkit_plugins/​ros2_medkit_opcua/​src/​opcua_client.cpp Sets the empty-array sentinel and updates the filter-builder namespace and call site.
src/​ros2_medkit_plugins/​ros2_medkit_opcua/​include/​ros2_medkit_opcua/​opcua_client.hpp Declares the filter builder in detail for test access.

Review effort: Balanced

The scan lambda runs on the sweep's worker threads. Two first probes could
both see the string empty and assign it at once, which ThreadSanitizer
reports as a race. A mutex around the check and the assignment fixes it.
@mfaferek93

Copy link
Copy Markdown
Collaborator Author

Superseded by #783, which carries this change as its own commit.

@mfaferek93 mfaferek93 closed this Nov 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants