Skip to content

fix(inputs.opcua): Disable auto-reconnect to fix session flood - #18813

Merged
srebhan merged 2 commits into
influxdata:masterfrom
skartikey:fix/opcua-disable-autoreconnect
Apr 29, 2026
Merged

srebhan merged 2 commits into
influxdata:masterfrom
skartikey:fix/opcua-disable-autoreconnect

Conversation

@skartikey

@skartikey skartikey commented Apr 28, 2026 •

Copy link
Copy Markdown
Contributor

Summary

inputs.opcua floods the server with sessions on outage, hitting BadTooManySessions. Reported in #18787. User logs over 2 min after a server restart: 6,410 CreateSessionRequest / 6,788 OpenSecureChannelRequest / 1 CloseSessionRequest. Peak CreateSession rate is 75-114/sec; Telegraf's own connect log fires only 1-4/sec, so the bulk isn't coming from Telegraf's reconnect path.

Source of the problem

Dual-ownership of reconnect between gopcua and Telegraf:

  1. gopcua defaults to AutoReconnect = true. Each client runs a background monitor that, on channel break, loops createSecureChannel -> restoreSession -> recreateSession with no backoff between failures. When the server is overloaded by N parallel clients, intermediate steps fail, leaving orphan sessions.
  2. Telegraf also reconnects via reconnect_error_threshold / forceReconnect / explicit Disconnect+Connect, and creates a fresh opcua.Client (and another monitor goroutine) each time.
  3. With 10 inputs on the same endpoint, both mechanisms run in parallel and sessions accumulate faster than session_timeout clears them.

Patched binary has been tested against Codesys reproducer over two server restarts (comment).

Metric Before (1 restart, 2 min) After (2 restarts, ~6 min)
CreateSessionRequest 6,410 51
OpenSecureChannelRequest 6,788 102
CloseSessionRequest 1 20
BadTooManySessions yes none

Checklist

Related issues

resolves #18787

The polling reader has no subscriptions to preserve across reconnects,
so gopcua's background reconnect loop only races with Telegraf's own
connect/disconnect cycle. On server restart this dual-ownership floods
the server with sessions and triggers BadTooManySessions. Disable the
library's auto-reconnect for the polling input so Telegraf is the sole
owner of reconnection.

The listener plugin still uses subscriptions and is left untouched.
@telegraf-tiger telegraf-tiger Bot added area/opcua fix pr to fix corresponding bug plugin/input 1. Request for new input plugins 2. Issues/PRs that are related to input plugins labels Apr 28, 2026
@skartikey skartikey self-assigned this Apr 28, 2026
@skartikey skartikey changed the title fix(inputs.opcua): Disable gopcua auto-reconnect to stop session floods fix(inputs.opcua): Disable auto-reconnect to fix session flood Apr 29, 2026
Merge TestGenerateClientOptsDisableAutoReconnect and
TestGenerateClientOptsWithLocales into a single table-driven
TestGenerateClientOptsExtras. Both shared the same
"base + variant + len(base)+1" shape, so the table is the natural fit.
@skartikey skartikey assigned srebhan and unassigned skartikey Apr 29, 2026
@skartikey skartikey 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 Apr 29, 2026
@telegraf-tiger

Copy link
Copy Markdown
Contributor

@srebhan srebhan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Awesome! Thanks @skartikey!

@srebhan
srebhan merged commit 7ff59b8 into influxdata:master Apr 29, 2026
5 checks passed
@github-actions github-actions Bot added this to the v1.38.4 milestone Apr 29, 2026
srebhan pushed a commit that referenced this pull request May 11, 2026
Stellar-roc pushed a commit to srp-devops/telegraf that referenced this pull request Jun 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/opcua fix pr to fix corresponding bug 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.

OPC-UA: Telegraf floods server with sessions on server restart

2 participants