From b490846d243294ee2ee5a838603ffbcfc013b653 Mon Sep 17 00:00:00 2001 From: Sven Rebhan <36194019+srebhan@users.noreply.github.com> Date: Thu, 1 May 2025 13:28:27 -0500 Subject: [PATCH] fix(common.ratelimiter): Only grow the buffer but never shrink (#16868) --- plugins/common/ratelimiter/serializers.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/common/ratelimiter/serializers.go b/plugins/common/ratelimiter/serializers.go index 6bd6ce78e..f3f0c632b 100644 --- a/plugins/common/ratelimiter/serializers.go +++ b/plugins/common/ratelimiter/serializers.go @@ -51,7 +51,7 @@ func (s *IndividualSerializer) SerializeBatch(metrics []telegraf.Metric, limit i // Grow the buffer so it can hold at least the required size. This will // save us from reallocate often s.buffer.Reset() - if limit > 0 && limit < int64(math.MaxInt) { + if limit > 0 && limit > int64(s.buffer.Cap()) && limit < int64(math.MaxInt) { s.buffer.Grow(int(limit)) }