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

ntpq input plugin: panicked: runtime error: index out of range [0] with length 0 #16090

Closed
flohoff opened this issue Oct 28, 2024 · 2 comments · Fixed by #16110
Closed

ntpq input plugin: panicked: runtime error: index out of range [0] with length 0 #16090

flohoff opened this issue Oct 28, 2024 · 2 comments · Fixed by #16110
Assignees
Labels
bug unexpected problem or unintended behavior waiting for response waiting for response from contributor

Comments

@flohoff
Copy link

flohoff commented Oct 28, 2024

Relevant telegraf.conf

[[inputs.ntpq]]
        # Disable nameserice lookup
        options = "-n"

Logs from Telegraf

Oct 28 18:11:50 telegraf-ntpd-host telegraf[313911]: 2024-10-28T17:11:50Z E! FATAL: [inputs.ntpq] panicked: runtime error: index out of range [0] with length 0, Stack:
Oct 28 18:11:50 telegraf-ntpd-host telegraf[313911]: goroutine 69 [running]:
Oct 28 18:11:50 telegraf-ntpd-host telegraf[313911]: github.com/influxdata/telegraf/agent.panicRecover(0xc0025a03f0)
Oct 28 18:11:50 telegraf-ntpd-host telegraf[313911]:         /go/src/github.com/influxdata/telegraf/agent/agent.go:1203 +0x70
Oct 28 18:11:50 telegraf-ntpd-host telegraf[313911]: panic({0x8b0a9c0?, 0xc0029ebf20?})
Oct 28 18:11:50 telegraf-ntpd-host telegraf[313911]:         /usr/local/go/src/runtime/panic.go:785 +0x132
Oct 28 18:11:50 telegraf-ntpd-host telegraf[313911]: github.com/influxdata/telegraf/plugins/inputs/ntpq.processLine({0x0?, 0x0?})
Oct 28 18:11:50 telegraf-ntpd-host telegraf[313911]:         /go/src/github.com/influxdata/telegraf/plugins/inputs/ntpq/ntpq.go:288 +0xfa
Oct 28 18:11:50 telegraf-ntpd-host telegraf[313911]: github.com/influxdata/telegraf/plugins/inputs/ntpq.(*NTPQ).gatherServer(0x40eebf?, {0xa109f40, 0xc002595920}, {0x0, 0x0})
Oct 28 18:11:50 telegraf-ntpd-host telegraf[313911]:         /go/src/github.com/influxdata/telegraf/plugins/inputs/ntpq/ntpq.go:162 +0x29a
Oct 28 18:11:50 telegraf-ntpd-host telegraf[313911]: github.com/influxdata/telegraf/plugins/inputs/ntpq.(*NTPQ).Gather(0xc002451400, {0xa109f40, 0xc002595920})
Oct 28 18:11:50 telegraf-ntpd-host telegraf[313911]:         /go/src/github.com/influxdata/telegraf/plugins/inputs/ntpq/ntpq.go:139 +0x3d
Oct 28 18:11:50 telegraf-ntpd-host telegraf[313911]: github.com/influxdata/telegraf/models.(*RunningInput).Gather(0xc0025a03f0, {0xa109f40, 0xc002595920})
Oct 28 18:11:50 telegraf-ntpd-host telegraf[313911]:         /go/src/github.com/influxdata/telegraf/models/running_input.go:232 +0x262
Oct 28 18:11:50 telegraf-ntpd-host telegraf[313911]: github.com/influxdata/telegraf/agent.(*Agent).gatherOnce.func1()
Oct 28 18:11:50 telegraf-ntpd-host telegraf[313911]:         /go/src/github.com/influxdata/telegraf/agent/agent.go:584 +0x58
Oct 28 18:11:50 telegraf-ntpd-host telegraf[313911]: created by github.com/influxdata/telegraf/agent.(*Agent).gatherOnce in goroutine 57
Oct 28 18:11:50 telegraf-ntpd-host telegraf[313911]:         /go/src/github.com/influxdata/telegraf/agent/agent.go:582 +0xf7
Oct 28 18:11:50 telegraf-ntpd-host telegraf[313911]: goroutine 1 [semacquire]:
Oct 28 18:11:50 telegraf-ntpd-host telegraf[313911]: sync.runtime_Semacquire(0xc002451590?)
Oct 28 18:11:50 telegraf-ntpd-host telegraf[313911]:         /usr/local/go/src/runtime/sema.go:71 +0x25
Oct 28 18:11:50 telegraf-ntpd-host telegraf[313911]: sync.(*WaitGroup).Wait(0xc00245c500?)
Oct 28 18:11:50 telegraf-ntpd-host telegraf[313911]:         /usr/local/go/src/sync/waitgroup.go:118 +0x48
Oct 28 18:11:50 telegraf-ntpd-host telegraf[313911]: github.com/influxdata/telegraf/agent.(*Agent).Run(0xc00245c500, {0xa0c54f0, 0xc002451540})
Oct 28 18:11:50 telegraf-ntpd-host telegraf[313911]:         /go/src/github.com/influxdata/telegraf/agent/agent.go:197 +0xa2a
Oct 28 18:11:50 telegraf-ntpd-host telegraf[313911]: main.(*Telegraf).runAgent(0xc00243e160, {0xa0c54f0, 0xc002451540}, 0x6?)
Oct 28 18:11:50 telegraf-ntpd-host telegraf[313911]:         /go/src/github.com/influxdata/telegraf/cmd/telegraf/telegraf.go:466 +0x1725
Oct 28 18:11:50 telegraf-ntpd-host telegraf[313911]: main.(*Telegraf).reloadLoop(0xc00243e160)
Oct 28 18:11:50 telegraf-ntpd-host telegraf[313911]:         /go/src/github.com/influxdata/telegraf/cmd/telegraf/telegraf.go:202 +0x26b
Oct 28 18:11:50 telegraf-ntpd-host telegraf[313911]: main.(*Telegraf).Run(0xc00243e160)
Oct 28 18:11:50 telegraf-ntpd-host telegraf[313911]:         /go/src/github.com/influxdata/telegraf/cmd/telegraf/telegraf_posix.go:19 +0xbc
Oct 28 18:11:50 telegraf-ntpd-host telegraf[313911]: main.runApp.func1(0xc002408fc0)
Oct 28 18:11:50 telegraf-ntpd-host telegraf[313911]:         /go/src/github.com/influxdata/telegraf/cmd/tele
Oct 28 18:11:50 telegraf-ntpd-host telegraf[313911]: 2024-10-28T17:11:50Z E! PLEASE REPORT THIS PANIC ON GITHUB with stack trace, configuration, and OS information: https://github.com/influxdata/telegraf/issues/new/choose

System info

Debian/Bookworm, telegraf (from deb) 1.32.1-1

Docker

No response

Steps to reproduce

Running the ntpq input plugin without "-n" works - disabling nameservice lookup and adding "-n" lets telegraf fail with a backtrace.

Expected behavior

No backtrace

Actual behavior

Backtrace in ntpq plugin

Additional info

root@telegraf-ntpd-host:~# ntpq -n -c pe
     remote                                   refid      st t when poll reach   delay   offset   jitter
=======================================================================================================
 0.europe.pool.ntp.org                   .POOL.          16 p    -  256    0   0.0000   0.0000   0.0001
 1.europe.pool.ntp.org                   .POOL.          16 p    -  256    0   0.0000   0.0000   0.0001
 2.europe.pool.ntp.org                   .POOL.          16 p    -  256    0   0.0000   0.0000   0.0001
 3.europe.pool.ntp.org                   .POOL.          16 p    -  256    0   0.0000   0.0000   0.0001
+172.31.2.111                            192.53.103.104   2 u  659 1024  377   0.1348  -4.5526   3.2355
+94.198.159.11                           .TMNL.           1 u  691 1024  377  17.4125  -2.2900   3.6388
*193.134.29.11                           .PTPs.           1 u 1018 1024  377  16.0927  -2.1828   1.4075
+178.239.19.57                           10.1.105.4       2 u  662 1024  377  19.2814  -2.3140   1.6363
+195.201.20.16                           100.10.69.89     2 u  607 1024  377  11.8093  -2.3424  19.6606
+213.157.100.71                          131.130.251.107  2 u  763 1024  377  22.3144  -1.9906   1.4815
+45.87.76.3                              244.220.219.218  2 u  863 1024  377  16.5980  -2.5092   1.9171

@flohoff flohoff added the bug unexpected problem or unintended behavior label Oct 28, 2024
@srebhan srebhan self-assigned this Oct 30, 2024
@srebhan
Copy link
Member

srebhan commented Oct 30, 2024

@flohoff I will add a fix to avoid the panic, but the reason you are running into this is that you are effectively running ntpq -n with your settings and this will open an ntpq shell as no command is specified... So set

[[inputs.ntpq]]
        # Disable nameserice lookup
        options = "-p -n"

@srebhan
Copy link
Member

srebhan commented Oct 30, 2024

@flohoff please test the binary in PR #16110, available as soon as CI finished the tests, and let me know if this fixes the issue!

@srebhan srebhan added the waiting for response waiting for response from contributor label Nov 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug unexpected problem or unintended behavior waiting for response waiting for response from contributor
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants