diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index c8e20b37325..8897e80cc9b 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -30,6 +30,8 @@ https://github.com/elastic/beats/compare/v6.2.0...6.2[Check the HEAD diff] *Affecting all Beats* +- Fix infinite loop when event unmarshal fails in Kubernetes pod watcher. {pull}6353[6353] + *Auditbeat* *Filebeat* diff --git a/libbeat/common/kubernetes/watcher.go b/libbeat/common/kubernetes/watcher.go index cf112dfe36b..2dfc7828345 100644 --- a/libbeat/common/kubernetes/watcher.go +++ b/libbeat/common/kubernetes/watcher.go @@ -3,6 +3,7 @@ package kubernetes import ( "context" "errors" + "io" "sync" "time" @@ -144,8 +145,16 @@ func (p *podWatcher) watch() { _, apiPod, err := watcher.Next() if err != nil { logp.Err("kubernetes: Watching API error %v", err) - watcher.Close() - break + + // In case of EOF, stop watching and restart the process + if err == io.EOF || err == io.ErrUnexpectedEOF { + watcher.Close() + time.Sleep(time.Second) + break + } + + // Otherwise, this is probably an unknown event (unmarshal error), ignore it + continue } // Update last resource version