Skip to content
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

Unchecked net.Listen() causes segfault in instrumental test #11092

Closed
setharnold opened this issue May 12, 2022 · 2 comments · Fixed by #11093
Closed

Unchecked net.Listen() causes segfault in instrumental test #11092

setharnold opened this issue May 12, 2022 · 2 comments · Fixed by #11093

Comments

@setharnold
Copy link

tcpServer, _ := net.Listen("tcp", "127.0.0.1:8000")

Hello, I'm taking a quick look at telegraf as part of the Ubuntu Main Inclusion process.

I had a problem building our package locally because I have a squid proxy running on localhost:8000.

This test case doesn't check the error return from net.Listen() and thus doesn't give a useful error message:

...
ok      github.com/influxdata/telegraf/plugins/outputs/health   0.019s
ok      github.com/influxdata/telegraf/plugins/outputs/http     5.055s
ok      github.com/influxdata/telegraf/plugins/outputs/influxdb 0.042s
ok      github.com/influxdata/telegraf/plugins/outputs/influxdb_v2      0.020s
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0x971eb1]

goroutine 20 [running]: 
github.com/influxdata/telegraf/plugins/outputs/instrumental.TCPServer.func1()
        /<<BUILDDIR>>/telegraf-1.21.4+ds1/plugins/outputs/instrumental/instrumental_test.go:85 +0x91
created by github.com/influxdata/telegraf/plugins/outputs/instrumental.TCPServer
        /<<BUILDDIR>>/telegraf-1.21.4+ds1/plugins/outputs/instrumental/instrumental_test.go:83 +0xcc
FAIL    github.com/influxdata/telegraf/plugins/outputs/instrumental     0.015s
ok      github.com/influxdata/telegraf/plugins/outputs/kafka    0.011s
ok      github.com/influxdata/telegraf/plugins/outputs/kinesis  0.044s
ok      github.com/influxdata/telegraf/plugins/outputs/librato  0.015s
...

No one expects test code to be perfect :) but it's pretty common for ports to collide, and a heads up that there was a simple error from a specific system call would be much easier to debug than a segmentation violation.

Thanks

powersj added a commit to powersj/telegraf that referenced this issue May 12, 2022
Rather than the user getting a seg vault to determine what the issue is,
instead catch any errors when trying to listen.

fixes: influxdata#11092
@powersj
Copy link
Contributor

powersj commented May 12, 2022

@setharnold!

Hello, I'm taking a quick look at telegraf as part of the Ubuntu Main Inclusion process.

I look forward to any improvements you suggest.

This test case doesn't check the error return from net.Listen() and thus doesn't give a useful error message:

I've put up #11093 after going through the test code and check the various net.Listen calls.

@setharnold
Copy link
Author

@powersj ! :D

#11093 looks great to me, thanks!

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

Successfully merging a pull request may close this issue.

2 participants