Skip to content

Commit

Permalink
ensure syslog parser gets an EOF-terminated reader on udp receive
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuapare committed Sep 26, 2023
1 parent 32f393d commit 92a23d5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ Main (unreleased)

- Fixed a bug where converting `YACE` cloudwatch config to river skipped converting static jobs. (@berler)

- Fixed a bug where UDP syslog messages were never processed (@joshuapare)

### Other changes

- Use Go 1.21.1 for builds. (@rfratto)
Expand Down
33 changes: 25 additions & 8 deletions component/loki/source/syslog/internal/syslogtarget/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package syslogtarget
// to other loki components.

import (
"bytes"
"context"
"crypto/tls"
"crypto/x509"
Expand Down Expand Up @@ -430,16 +431,32 @@ func (t *UDPTransport) handleRcv(c *ConnPipe) {
defer t.openConnections.Done()

lbs := t.connectionLabels(c.addr.String())
err := syslogparser.ParseStream(c, func(result *syslog.Result) {
if err := result.Error; err != nil {
t.handleMessageError(err)
} else {
t.handleMessage(lbs.Copy(), result.Message)

for {
datagram := make([]byte, t.maxMessageLength())
n, err := c.Read(datagram)
if err != nil {
if err == io.EOF {
break
}

level.Warn(t.logger).Log("msg", "error reading from pipe", "err", err)
continue
}
}, t.maxMessageLength())

if err != nil {
level.Warn(t.logger).Log("msg", "error parsing syslog stream", "err", err)
r := bytes.NewReader(datagram[:n])

err = syslogparser.ParseStream(r, func(result *syslog.Result) {
if err := result.Error; err != nil {
t.handleMessageError(err)
} else {
t.handleMessage(lbs.Copy(), result.Message)
}
}, t.maxMessageLength())

if err != nil {
level.Warn(t.logger).Log("msg", "error parsing syslog stream", "err", err)
}
}
}

Expand Down

0 comments on commit 92a23d5

Please sign in to comment.