From eee4c711a218cd9be8d8668d278efbbecc844462 Mon Sep 17 00:00:00 2001 From: Vlad Hanciuta Date: Tue, 5 Dec 2017 14:04:35 +0000 Subject: [PATCH] Check for insufficient data when we try to get the records. In some corner cases (like v2 records produced on the topic but the sarama consumer uses v0 Fetch API with a limit less than one record size) we might receive a truncated record batch. We want to be able to make progress by increasing the fetch limit, so don't return an error, but rater mark the batch as partial trailing record. --- record_batch.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/record_batch.go b/record_batch.go index 3c148be58..a8c533b17 100644 --- a/record_batch.go +++ b/record_batch.go @@ -161,6 +161,11 @@ func (b *RecordBatch) decode(pd packetDecoder) (err error) { bufSize := int(batchLen) - recordBatchOverhead recBuffer, err := pd.getRawBytes(bufSize) if err != nil { + if err == ErrInsufficientData { + b.PartialTrailingRecord = true + b.Records = nil + return nil + } return err }