Skip to content

fix(plugins.snmp): Update gosnmp to prevent panic in snmp agents #17367

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

Merged
merged 1 commit into from
Jul 23, 2025

Conversation

stepga
Copy link
Contributor

@stepga stepga commented Jul 21, 2025

As described in the respective gosnmp issue [1], gosnmp improperly handled an EOF/closed connection during a SNMP over TCP session.

This led to huge telegraf logs full of stack traces.

The issue has been fixed gosnmp v1.42.1 [2].

[1] gosnmp/gosnmp#521
[2] https://github.com/gosnmp/gosnmp/releases/tag/v1.42.1

Summary

Checklist

  • No AI generated code was used in this PR

Related issues

resolves #17366

@telegraf-tiger telegraf-tiger bot added area/snmp fix pr to fix corresponding bug labels Jul 21, 2025
Copy link
Contributor

@skartikey skartikey left a comment

Choose a reason for hiding this comment

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

@stepga Thanks for reporting this and putting up the PR!

You're right about the version bump: gosnmp v1.41.0 → v1.42.1, this is needed and correctly addresses the panic.

However, the line change from &params to params seems unrelated and potentially incorrect: It’s not tied to the EOF panic, that issue is entirely within gosnmp see issue #521, PR #522
It could break behavior by changing how the trap listener receives parameters

Suggestion:
Keep the version bump
Drop the &params → params change, it’s unnecessary for fixing the issue and could introduce side effects.

The dependency update alone resolves the panic.

@stepga
Copy link
Contributor Author

stepga commented Jul 22, 2025

Hey @skartikey, thanks for reviewing the PR!

However, the line change from &params to params seems unrelated and potentially incorrect: It’s not tied to the EOF panic, that issue is entirely within gosnmp see issue #521, PR #522 It could break behavior by changing how the trap listener receives parameters
Suggestion: Keep the version bump Drop the &params → params change, it’s unnecessary for fixing the issue and could introduce side effects.
The dependency update alone resolves the panic.

You are right: the code change in plugins/inputs/snmp_trap/snmp_trap.go is not tied to the EOF panic.
This change is needed to make the lint-linux pipeline happy.

Of course, my first PR draft modified only go.sum and go.mod to bump the gosnmp module, see 1f4aa48.
However, this change broke the lint-linux pipeline job (see [1]).
You can test it yourself:

$ make check
go vet $(go list ./... | grep -v ./plugins/parsers/influx)
# github.com/influxdata/telegraf/plugins/inputs/snmp_trap
# [github.com/influxdata/telegraf/plugins/inputs/snmp_trap]
plugins/inputs/snmp_trap/snmp_trap.go:92:12: assignment copies lock value to params: github.com/gosnmp/gosnmp.GoSNMP contains sync.Mutex

go vet has found suspicious constructs. Please remediate any reported errors
to fix them before submitting code for review.
make: *** [Makefile:173: vet] Error 1

This go vet fail is due to a change within the GoSNMP struct (c.f. gosnmp/gosnmp#520).
The respective change adds a mutex to the struct to ensure a safe concurrent closing of the underlying connection.

As gosnmp.Default is a pointer to a global struct containing sensible defaults, you might be right about the
change being "potentially incorrect" ...

IMO the safe fix here would be to explicitly create a new local struct with the global gosnmp.Default's values.

[1] https://app.circleci.com/pipelines/github/influxdata/telegraf/26915/workflows/f323c556-830a-440e-9d2d-d7c1ad319409/jobs/424180

As described in the respective gosnmp issue [1], gosnmp improperly
handled an EOF/closed connection during a SNMP over TCP session.

This led to huge telegraf logs full of stack traces.
The issue has been fixed gosnmp v1.42.1 [2].

Also, adapt to the new `gosnmp` version, and make `make check`
pass (see plugins/inputs/snmp_trap/snmp_trap.go).

[1] gosnmp/gosnmp#521
[2] https://github.com/gosnmp/gosnmp/releases/tag/v1.42.1

resolves influxdata#17366

Signed-off-by: Stephan Gabert <stepga@nirgendwo.eu>
@telegraf-tiger
Copy link
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 doesn't significantly change the Telegraf binary size (less than 1%)

📦 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 ]]

@skartikey
Copy link
Contributor

@stepga Got the full picture now, great catch on both issues!

1)The gosnmp upgrade to v1.42.1 resolves the TCP EOF panic issue #521
2) The refactor avoids copying the sync.Mutex in GoSNMP, fixing the govet warning

Your explicit struct initialization is cleaner, avoids hidden bugs, and improves maintainability. Nicely done!

Copy link
Contributor

@skartikey skartikey left a comment

Choose a reason for hiding this comment

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

@stepga Thanks for the contribution!

@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 Jul 23, 2025
@mstrandboge mstrandboge merged commit 8fd174c into influxdata:master Jul 23, 2025
27 checks passed
@github-actions github-actions bot added this to the v1.35.3 milestone Jul 23, 2025
skartikey pushed a commit that referenced this pull request Jul 28, 2025
)

Signed-off-by: Stephan Gabert <stepga@nirgendwo.eu>
Co-authored-by: Stephan Gabert <stepga@nirgendwo.eu>
(cherry picked from commit 8fd174c)
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 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.

Telegraf snmp agent panic due to nil pointer reference in gosnmp
3 participants