influxdata / influxdata/telegraf

inputs.opcua_listener: permanent disconnect when subscription recreation fails with StatusBadNodeIDUnknown

Open
#19,186 2 comments 0 reactions 1 assignee Claimed by @skartikey View on GitHub
area/opcua bug upstream
Dominant language
Go
Stars
17.8k
Forks
5.8k
Avg merge
1d 20h
Merged PRs (30d)
161

Description

### Use Case

Telegraf should recover from OPC UA connection drops and re-establish its subscriptions. When a subscription cannot be recreated because one or more monitored node IDs are no longer valid, Telegraf should keep retrying the connection instead of giving up permanently.

### Expected behavior

After a connection drop, `opcua_listener` re-establishes the session and resumes data collection, or keeps attempting to reconnect until it succeeds.

### Actual behavior

After an intermittent network drop, gopcua's auto-reconnect runs but ends in a permanent disconnect:

- `restoreSession` fails with `StatusBadSessionIDInvalid`
- `recreateSession` succeeds
- `transferSubscriptions` fails, so `restoreSubscriptions` runs
- the subscription is recreated, but registration fails with `StatusBadNodeIDUnknown (0x80340000)` because one or more monitored node IDs are no longer valid in the server address space

gopcua then logs `no subscriptions to resume` and Telegraf stays permanently disconnected with no further reconnection attempts. Restarting Telegraf is the only way to recover.

### Logs from Telegraf

```text
debug: publish: error: unexpected error. Do we need to stop the publish loop?: The session was closed by the client. StatusBadSessionClosed (0x80260000)
debug: sub: error: The session was closed by the client. StatusBadSessionClosed (0x80260000)
debug: client: monitor: disconnected
debug: client: monitor: auto-reconnecting
debug: client: monitor: action: createSecureChannel
debug: client: monitor: secure channel recreated
debug: client: monitor: action: restoreSession
debug: client: monitor: trying to restore session
debug: client: monitor: restore session failed: The session id is not valid. StatusBadSessionIDInvalid (0x80250000)
debug: client: monitor: action: recreateSession
debug: client: monitor: trying to recreate session
debug: client: monitor: session recreated
debug: client: monitor: trying to update namespaces
debug: client: monitor: namespaces updated
debug: client: monitor: action: transferSubscriptions
debug: client: monitor: sub 6647: transfer subscription failed
debug: client: monitor: action: restoreSubscriptions
debug: sub 6647: recreate_delete: subscription deleted
debug: sub 6647: recreate_create: recreated as subscription 8581
sub 8581: recreate: subscription registered
debug: client: monitor: recreate subscripitions failed: The node id refers to a node that does not exist in the server address space. StatusBadNodeIDUnknown (0x80340000)
debug: client: monitor: no subscriptions to resume
```

### Steps to reproduce

1. Configure `opcua_listener` with a subscription to monitored items.
2. Trigger an intermittent network drop between the OPC UA server and Telegraf so the session is closed.
3. Have one or more monitored node IDs become invalid on the server during the outage.
4. Observe that auto-reconnect recreates the session but fails to recreate the subscription with `StatusBadNodeIDUnknown`, after which Telegraf stays disconnected.

### Additional info

Information needed to reproduce and triage: Telegraf version, gopcua version, full `opcua_listener` configuration, and complete debug logs.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.