fix(agent): Catch panics in inputs goroutine (#14840)

This commit is contained in:
Mingyang Zheng 2024-02-26 11:59:16 -08:00 committed by GitHub
parent c5ee403e9d
commit 6d523c96f3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 2 additions and 3 deletions

View File

@ -556,8 +556,6 @@ func (a *Agent) gatherLoop(
ticker Ticker, ticker Ticker,
interval time.Duration, interval time.Duration,
) { ) {
defer panicRecover(input)
for { for {
select { select {
case <-ticker.Elapsed(): case <-ticker.Elapsed():
@ -581,6 +579,7 @@ func (a *Agent) gatherOnce(
) error { ) error {
done := make(chan error) done := make(chan error)
go func() { go func() {
defer panicRecover(input)
done <- input.Gather(acc) done <- input.Gather(acc)
}() }()
@ -1200,7 +1199,7 @@ func panicRecover(input *models.RunningInput) {
runtime.Stack(trace, true) runtime.Stack(trace, true)
log.Printf("E! FATAL: [%s] panicked: %s, Stack:\n%s", log.Printf("E! FATAL: [%s] panicked: %s, Stack:\n%s",
input.LogName(), err, trace) input.LogName(), err, trace)
log.Println("E! PLEASE REPORT THIS PANIC ON GITHUB with " + log.Fatalln("E! PLEASE REPORT THIS PANIC ON GITHUB with " +
"stack trace, configuration, and OS information: " + "stack trace, configuration, and OS information: " +
"https://github.com/influxdata/telegraf/issues/new/choose") "https://github.com/influxdata/telegraf/issues/new/choose")
} }