Fix syslog server silently dropping packets under load

The syslog parser reuses its result map for each line it parses, and
SyslogMsg kept a reference to that map instead of a copy. The producer
consumes messages concurrently with the reader, so by the time a message
was checked, its map had sometimes already been overwritten by the next
line; the message then failed the 'KafkatorioPacket:::' filter and was
dropped without any log. Under real load (bursts of map chunk packets)
most packets were lost.

Copy the parsed map, and log Kafka producer send failures instead of
ignoring them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Lazzexus 2026-10-12 18:58:21 +02:00
parent 5f7a631936
commit fa28cd9713
2 changed files with 5 additions and 3 deletions

View file

@ -128,7 +128,7 @@ class KafkatorioPacketKafkaProducer(
syslog.copyHeadersTo(record)
producer.send(record)
producer.send(record) { _, ex -> if (ex != null) log("failed to send packet: ${ex::class.qualifiedName} ${ex.message}") }
}
@ -143,7 +143,7 @@ class KafkatorioPacketKafkaProducer(
syslog.copyHeadersTo(record)
dlqProducer.send(record)
dlqProducer.send(record) { _, ex -> if (ex != null) log("failed to send DLQ message: ${ex::class.qualifiedName} ${ex.message}") }
}

View file

@ -87,7 +87,9 @@ class SyslogSocketServer(
try {
val messageContents = syslogParser.parseLine(line)
val syslog = SyslogMsg(messageContents)
// copy the result: the parser reuses its map for the next line, so without a copy a
// message could be overwritten before it was produced, and was then silently dropped
val syslog = SyslogMsg(messageContents.toMap())
_messages.emit(syslog)
} catch (ex: ParseException) {
log("ignoring non-syslog message: $line")