Skip to content

Commit

Permalink
Promtail: handling tight loop in journal follow logic (#4066)
Browse files Browse the repository at this point in the history
* Handling EBADMSG explicitly, and preventing tight loop

Signed-off-by: Danny Kopping <danny.kopping@grafana.com>

* Appeasing the linter

Signed-off-by: Danny Kopping <danny.kopping@grafana.com>
  • Loading branch information
Danny Kopping authored Jul 28, 2021
1 parent 19aec6e commit a3414a5
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions clients/pkg/promtail/targets/journal/journaltarget.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"io"
"io/ioutil"
"strings"
"syscall"
"time"

"github.com/coreos/go-systemd/sdjournal"
Expand Down Expand Up @@ -182,11 +183,16 @@ func journalTargetWithReader(
for {
err := t.r.Follow(until, ioutil.Discard)
if err != nil {
if err == sdjournal.ErrExpired || err == io.EOF {
level.Error(t.logger).Log("msg", "received error during sdjournal follow", "err", err.Error())

if err == sdjournal.ErrExpired || err == syscall.EBADMSG || err == io.EOF {
level.Error(t.logger).Log("msg", "unable to follow journal", "err", err.Error())
return
}
level.Error(t.logger).Log("msg", "received error during sdjournal follow", "err", err.Error())
}

// prevent tight loop
time.Sleep(100 * time.Millisecond)
}
}()

Expand Down

0 comments on commit a3414a5

Please sign in to comment.