-
Notifications
You must be signed in to change notification settings - Fork 5.7k
fix(inputs.opcua): Handle session invalidation between gather cycles #16854
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(inputs.opcua): Handle session invalidation between gather cycles #16854
Conversation
056d039 to
10a0cec
Compare
srebhan
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @skartikey for the fix! Some comments/questions in the code...
When use_unregistered_reads=true is configured, the client still attempts to use the previous session on subsequent reads, leading to alternating success/failure patterns when the server invalidates the session (StatusBadSessionIDInvalid errors). This fix adds session state tracking to properly reconnect after session errors, ensuring consistent data collection regardless of whether registered or unregistered reads are used. Also adds tests to verify session recovery behavior.
Co-authored-by: Sven Rebhan <[email protected]>
3fa005f to
55a5213
Compare
srebhan
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the update @skartikey! Some more comments...
|
Download PR build artifacts for linux_amd64.tar.gz, darwin_arm64.tar.gz, and windows_amd64.zip. 📦 Click here to get additional PR build artifactsArtifact URLs |
srebhan
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @skartikey!
|
FYI: #17014 |
|
I tried running the latest code (1.34.4) and I am still seeing the alternating success/failure loop. Reading through the code it seems like this PR didn't really fix the core problem as it still needs to detect a failure before performing a full reconnect attempt. When I am doing long polling intervals (greater than 1m) I always get a failure in between each success. Maybe I am misunderstanding how to properly use this new code. What specific settings should I be using to prevent the alternating failure scenario? If I am polling with long intervals I would like to be able to FORCE a full reconnect on every read attempt, is that possible? |
|
@jminardi I did some investigation and this is what's happening. The
Currently, the code prevents setting The fix will distinguish between "not configured" (uses default of 1) versus "explicitly set to 0" (forces reconnection every cycle), giving you the proactive reconnection behavior you need to eliminate the alternating success/failure pattern. |
|
@skartikey Thank you, that sounds perfect! |
Summary
The OPC UA plugin encountered an alternating success/failure pattern when using the
use_unregistered_reads = truesetting. This manifested as:StatusBadSessionIDInvaliderrorThis occurred because even with
use_unregistered_reads = true, the plugin wasn't properly handling session invalidation between gather cycles. When a server invalidated the session (which happens periodically in most OPC UA servers), the client attempted to use the same session on the next read operation. Since the session was no longer valid, this caused errors every other gather cycle.Fix Details
The fix addresses this by:
lastSessionErrorflag to track when session errors occurThese changes ensure that after a session error, the next gather cycle performs a full reconnection and establishes a fresh session, rather than trying to reuse the invalid one.
Checklist
Related issues
resolves #16735