Repository navigation
feat(opcua): x-plc-status says why the link to the server is down - #779
Closed
mfaferek93 wants to merge 4 commits into
Closed
mfaferek93 wants to merge 4 commits into
mfaferek93 wants to merge 4 commits 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).
x-plc-status gains last_error, the OPC UA status name of the last failure: a refused server certificate, an ERR from a server that refuses the client's certificate, a refused user, a timeout. open62541 1.3 ends a refused channel with BadConnectionClosed and only logs why, so the reason is taken from the client's certificate check and from the server's ERR message.
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved issues leave /x-plc-status blocked during stalled reconnects and allow connection, security-configuration, and single-value read failures to be omitted or misreported.
5 open issues
Incomplete ERR allowlist hides valid server refusal statuses · New Malformed security files may be accepted as valid configuration · New Single-value read failures are not recorded · New Dropped sessions can leave last_error empty or stale · New Status endpoint blocks on the connection mutex during reconnects · New
What changed in this PR
Adds last_error to the OPC UA plugin’s x-plc-status endpoint so gateway clients can distinguish connection, security, and read failures.
Changes:
- Tracks failure status names and clears the diagnostic after a successful connection.
- Captures certificate-verification and server ERR reasons that would otherwise appear as generic connection failures.
- Adds failure-reporting tests and documents the field in the package README.
| File | Description |
|---|---|
src/ros2_medkit_plugins/ros2_medkit_opcua/test/test_opcua_client.cpp |
Checks initial, failed-connect, and configuration-error diagnostics. |
src/ros2_medkit_plugins/ros2_medkit_opcua/test/integration/test_opcua_secured.test.py |
Adds status assertions for password and certificate refusals. |
src/ros2_medkit_plugins/ros2_medkit_opcua/src/opcua_plugin.cpp |
Exposes last_error in the status response. |
src/ros2_medkit_plugins/ros2_medkit_opcua/src/opcua_client.cpp |
Implements failure tracking and certificate/logger interception. |
src/ros2_medkit_plugins/ros2_medkit_opcua/README.md |
Documents the response field and its lifecycle. |
src/ros2_medkit_plugins/ros2_medkit_opcua/include/ros2_medkit_opcua/opcua_client.hpp |
Declares and documents the diagnostic accessor. |
Review effort: Balanced
Comment on lines
+297
to
+301
| for (UA_StatusCode code : {UA_STATUSCODE_BADSECURITYCHECKSFAILED, UA_STATUSCODE_BADCERTIFICATEUNTRUSTED, | ||
| UA_STATUSCODE_BADCERTIFICATEINVALID, UA_STATUSCODE_BADCERTIFICATETIMEINVALID, | ||
| UA_STATUSCODE_BADCERTIFICATEURIINVALID, UA_STATUSCODE_BADCERTIFICATEREVOKED, | ||
| UA_STATUSCODE_BADCERTIFICATEUSENOTALLOWED, UA_STATUSCODE_BADSECURITYPOLICYREJECTED, | ||
| UA_STATUSCODE_BADTCPENDPOINTURLINVALID, UA_STATUSCODE_BADTCPMESSAGETOOLARGE}) { |
Comment on lines
+672
to
+674
| if (!apply_security_config(impl_->client, config)) { | ||
| impl_->connected = false; | ||
| impl_->set_last_error(UA_StatusCode_name(UA_STATUSCODE_BADCONFIGURATIONERROR)); |
| r.good = true; | ||
| } catch (const opcua::BadStatus & e) { | ||
| r.good = false; | ||
| impl_->set_last_error(UA_StatusCode_name(e.code())); |
Comment on lines
+1880
to
+1882
| if (connect_status != UA_STATUSCODE_GOOD) { | ||
| impl_->set_last_error(UA_StatusCode_name(connect_status)); | ||
| } |
| j["write_capable"] = MEDKIT_OPCUA_READ_ONLY == 0; | ||
| j["poll_count"] = snap.poll_count; | ||
| j["error_count"] = snap.error_count; | ||
| j["last_error"] = client_->last_error(); |
…s-client' into fix/opcua-status-says-why-it-is-down
…n policy says so A channel left open by a refused ActivateSession read as connected through open62541pp's isConnected(), so x-plc-status said connected and every read failed. Only an activated session counts now. A server that offers no token policy for the configured user is reported as BadIdentityTokenInvalid instead of open62541's BadInternalError. Built on the secured config lifetime fix.
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
GET /components/{id}/x-plc-statusof the OPC UA plugin gainslast_error: the OPC UA status name of the last failure of the link.BadCertificateUntrusted(the server's certificate is not in the trust list), the status of the server's ERR message such asBadSecurityChecksFailed(the server does not trust the client's certificate),BadUserAccessDenied(a refused user),BadIdentityTokenInvalid(no token policy of the server takes the configured user, e.g. anonymous on a server that wants a user),BadTimeout/BadConnectionClosed(nothing answers)BadConfigurationErrorwhen the client's own certificate, key or security settings could not be appliedIt is cleared by a connect that succeeds. It has its own lock, so the route never waits behind a connect in progress.
Two fixes on the way:
isConnected(). The fast path ofconnect()returned true,x-plc-statussaidconnected: trueand every read failed. Only an activated session counts now.main(SIGBUS inUA_ChannelModule_Aes128Sha256RsaOaep_Delete_Context, logging through a policy context's logger pointer to a dead stack frame). fix(opcua): keep a secured client's config alive as long as the client #778 fixes that, so this branch merges fix(opcua): keep a secured client's config alive as long as the client #778 and should land after it.Why
A client of the gateway saw
connected: falseand nothing else. A missing trust entry on either side, a wrong user and a server that is off all looked the same.open62541 1.3 ends a refused channel with
BadConnectionClosed(ua_client.creceiveResponse) and a missing token policy withBadInternalError, and only logs why.connectStatusholds the same codes. So the client puts two taps on its own config: one in front of the certificate check of the server's certificate, and one in front of the logger that matches the exact format strings ofprocessERRResponseand of the token policy selection. Both forward to the original plugin.Tests
test_opcua_client: a refused port names aBad...status that is not a certificate one, a contradictory security config givesBadConfigurationError, a new client has none.test_opcua_secured(real open62541 server, Basic256Sha256 SignAndEncrypt):connected == false,last_error == BadUserAccessDeniedconnected == false,last_error == BadCertificateUntrusted, no value served. Without the taps this readsBadConnectionClosed.last_error == BadSecurityChecksFailedconnected == false,last_error == BadIdentityTokenInvalid. Without the session check this readsconnected: truewith every read failing.ROS2_MEDKIT_OPCUA_SECURE_REQUIRE=1, clang-format clean. Debug build ofmainplus the session check: SIGBUS on the third connect of a refused session; with fix(opcua): keep a secured client's config alive as long as the client #778: none.