Skip to content

fix(inputs.snmp): Drop the connection to an agent after a failed gather - #19855

Open
skartikey wants to merge 1 commit into
influxdata:masterfrom
skartikey:fix-snmp-drop-connection-on-error
Open

skartikey wants to merge 1 commit into
influxdata:masterfrom
skartikey:fix-snmp-drop-connection-on-error

Conversation

@skartikey

@skartikey skartikey commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Summary

inputs.snmp keeps one connection per agent for the life of the process and only ever reconnects when the socket is gone. For SNMPv3 that connection also holds the engine ID discovered on the first request. When the agent restarts with a new engine ID, it answers with an unauthenticated usmStatsUnknownEngineIDs report, which gosnmp rejects as not authentic before it can act on it, so every gather fails until Telegraf is restarted. The same stale connection keeps a hostname resolved to an address that no longer answers.

This closes and drops the cached connection when gathering from an agent fails, so the next interval sets up a fresh one and runs the engine discovery again. That is what a restart does today. It applies to all SNMP versions as it also re-resolves the agent address, and the cost is one socket and, for SNMPv3, one discovery exchange per failed interval. Close is added to the snmp.Connection interface for this, the wrapper already provides it.

Checklist

Related issues

resolves #19816
related to #16880

@telegraf-tiger telegraf-tiger Bot added area/snmp fix pr to fix corresponding bug plugin/input 1. Request for new input plugins 2. Issues/PRs that are related to input plugins labels Oct 7, 2026
@telegraf-tiger

telegraf-tiger Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

Download PR build artifacts for linux_amd64.tar.gz, darwin_arm64.tar.gz, and windows_amd64.zip.
Downloads for additional architectures and packages are available below.

⚠️ This pull request increases the Telegraf binary size by 5.91 % for linux amd64 (new size: 326.5 MB, nightly size 308.2 MB)

📦 Click here to get additional PR build artifacts

Artifact URLs

. DEB . RPM . TAR . GZ . ZIP
amd64.deb aarch64.rpm darwin_amd64.tar.gz windows_amd64.zip
arm64.deb armel.rpm darwin_arm64.tar.gz windows_arm64.zip
armel.deb armv6hl.rpm freebsd_amd64.tar.gz windows_i386.zip
armhf.deb i386.rpm freebsd_armv7.tar.gz
i386.deb ppc64le.rpm freebsd_i386.tar.gz
mips.deb riscv64.rpm linux_amd64.tar.gz
mipsel.deb s390x.rpm linux_arm64.tar.gz
ppc64el.deb x86_64.rpm linux_armel.tar.gz
riscv64.deb linux_armhf.tar.gz
s390x.deb linux_i386.tar.gz
linux_mips.tar.gz
linux_mipsel.tar.gz
linux_ppc64le.tar.gz
linux_riscv64.tar.gz
linux_s390x.tar.gz

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/snmp fix pr to fix corresponding bug plugin/input 1. Request for new input plugins 2. Issues/PRs that are related to input plugins

Projects

None yet

Development

Successfully merging this pull request may close these issues.

inputs.snmp: SNMPv3 polling never recovers after the agent restarts with a new engine ID

1 participant