Skip to content

Commit

Permalink
Avoid infinite loop in Kubernetes watcher
Browse files Browse the repository at this point in the history
In case of unmarshalling errors the Watcher was ending up in a infinite loop,
this code ignores those errors and only restarts the watcher in case of
EOF.
  • Loading branch information
Carlos Pérez-Aradros Herce committed Feb 12, 2018
1 parent 0735c81 commit 32debe1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -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*
Expand Down
13 changes: 11 additions & 2 deletions libbeat/common/kubernetes/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package kubernetes
import (
"context"
"errors"
"io"
"sync"
"time"

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 32debe1

Please sign in to comment.