Repository navigation
fix(opcua): keep a secured client's config alive as long as the client - #778
Closed
mfaferek93 wants to merge 1 commit into
Closed
mfaferek93 wants to merge 1 commit into
mfaferek93 wants to merge 1 commit into
Conversation
open62541 1.3 security policy contexts keep a pointer to the logger of the config they were built in. That config was a local of the connect call, so the log line on closing a secured channel read a dead stack frame, and a dropped link crashed the gateway (SIGSEGV in UA_ChannelModule_Delete_Context).
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are reported for the change addressing the secured OPC UA client’s logger lifetime.
No open issues 🎉
What changed in this PR
Fixes a secured OPC UA client crash when a connection drops by keeping the configuration’s logger alive for the lifetime of the client that references it.
Changes:
- Retains the security configuration on the heap and preserves its lifetime during client replacement and destruction.
- Adds a regression test covering secured connection loss, reconnect, and explicit disconnect after stack memory is overwritten.
- Provides the reconnect test with the certificate-generation script path.
| File | Description |
|---|---|
src/ros2_medkit_plugins/ros2_medkit_opcua/test/test_opcua_client_reconnect.cpp |
Adds a secured-server fixture and logger-lifetime regression test. |
src/ros2_medkit_plugins/ros2_medkit_opcua/src/opcua_client.cpp |
Keeps the security configuration alive until its associated client is destroyed. |
src/ros2_medkit_plugins/ros2_medkit_opcua/CMakeLists.txt |
Exposes the certificate-generation script path to the reconnect test. |
Review effort: Balanced
This was referenced Nov 9, 2026
Collaborator
Author
|
Superseded by #783, which carries this change as its own commit. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
A gateway connected to a secured OPC UA server (Basic256Sha256, SignAndEncrypt) crashed with SIGSEGV when the link dropped:
In open62541 1.3 (bundled by open62541pp v0.16), each security policy context stores a pointer to the logger of the
UA_ClientConfigit was built in.apply_security_configbuilt that config as a localopcua::ClientConfigand moved it into the client. The existing 1.3 workaround re-pointssecurityPolicies[i].logger, but the policy context keeps its own copy of the pointer (ua_openssl_basic256sha256.c,cc->policyContext->logger). Onceconnect()returned, that pointer led into a dead stack frame. Closing a secured channel logs through it, so the crash came whenever that stack memory had been reused before the next link drop.Fix
The config lives on the heap in
OpcuaClient::Impl(declared beforeclient, so it is destroyed after it) and is replaced only once the client built from the next one is in place. After the move it holds a default config, so the policy context logs through a valid stdout logger.Testing
SecuredOpcuaClientReconnect.ChannelClosesAfterConnectReturned: secured connect totest_alarm_server --securebehind the link proxy, overwrite the dead stack, cut the link, pump until the channel closes, reconnect, disconnect. Without the fix it dies deterministically with SIGBUS at0xa5a5a5a5a5a5a5a5inUA_ChannelModule_Delete_Context, the stack seen in the field. With the fix it passes (3 of 3 runs).colcon test --packages-select ros2_medkit_opcua: all tests pass, clang-format clean.