Skip to content

Conversation

skartikey
Copy link
Contributor

Summary

This issue was raised in this comment following our recent work on handling session invalidation between gather cycles.

Problem

Users with long polling intervals (>1 minute) experience alternating success/failure patterns due to OPC UA session timeouts. The current implementation prevents setting reconnect_error_threshold = 0 because it forces zero values to default to 1, making it impossible to achieve proactive reconnection behavior.

Root Cause

With long polling intervals, OPC UA sessions often become stale between reads, leading to this cycle:

  1. First read fails (stale session detected)
  2. Reconnection is forced for next cycle
  3. Second read succeeds (fresh session)
  4. Session becomes stale again during long wait
  5. Cycle repeats

The fix is to allow setting reconnect_error_threshold = 0 so that it can reconnect on every gather cycle.

Configuration Examples

# Not configured - uses default of 1 (reconnect after first error)
# reconnect_error_threshold = 

# Set to 0 - forces reconnection every gather (ideal for long polling)
reconnect_error_threshold = 0

# Set to 3 - reconnects after 3 consecutive errors
reconnect_error_threshold = 3

Checklist

  • No AI generated code was used in this PR

Related issues

resolves #

@telegraf-tiger telegraf-tiger bot added area/opcua feat Improvement on an existing feature such as adding a new setting/mode to an existing plugin plugin/input 1. Request for new input plugins 2. Issues/PRs that are related to input plugins labels May 23, 2025
@srebhan srebhan changed the title feat(inputs.opcua): Allow reconnect_error_threshold=0 to force reconnection on every gather cycle feat(inputs.opcua): Allow forcing reconnection on every gather cycle Jun 12, 2025
Copy link
Member

@srebhan srebhan left a comment

Choose a reason for hiding this comment

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

@skartikey just one more small suggestion...

srebhan
srebhan previously approved these changes Jun 13, 2025
Copy link
Member

@srebhan srebhan left a comment

Choose a reason for hiding this comment

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

Thanks @skartikey!

@srebhan srebhan dismissed their stale review June 13, 2025 09:52

Sorry, didn't see the failing linter. Please check those!

skartikey and others added 4 commits June 13, 2025 14:19
…econnection

Change ReconnectErrorThreshold from uint64 to *uint64 to distinguish between unset (nil) and explicitly set to zero
Allow reconnect_error_threshold=0 to force reconnection every gather cycle
Maintain backward compatibility with default threshold of 1
Add comprehensive test coverage for threshold scenarios (0, 1, 3)
Fix alternating success/failure pattern for long polling intervals

This enables users with long polling intervals (>1 min) to avoid OPC UA
session timeout issues by forcing fresh connections on every read.
Co-authored-by: Sven Rebhan <36194019+srebhan@users.noreply.github.com>
@skartikey skartikey force-pushed the inputs_opcua_enable_reconnection branch from 04637ef to 54c69a3 Compare June 13, 2025 13:19
Copy link
Member

@srebhan srebhan left a comment

Choose a reason for hiding this comment

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

Thanks @skartikey!

@srebhan srebhan added the ready for final review This pull request has been reviewed and/or tested by multiple users and is ready for a final review. label Jun 13, 2025
@srebhan srebhan assigned mstrandboge and unassigned srebhan Jun 13, 2025
@mstrandboge mstrandboge merged commit 4330a36 into influxdata:master Jun 13, 2025
22 of 24 checks passed
@github-actions github-actions bot added this to the v1.35.0 milestone Jun 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/opcua feat Improvement on an existing feature such as adding a new setting/mode to an existing plugin plugin/input 1. Request for new input plugins 2. Issues/PRs that are related to input plugins ready for final review This pull request has been reviewed and/or tested by multiple users and is ready for a final review.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants