From de2988ad33f9ffafa6d35ae5186cd6a68ce048a4 Mon Sep 17 00:00:00 2001 From: ANDREY KHASANOV Date: Fri, 22 Dec 2023 19:40:07 +0200 Subject: [PATCH] Fixed potential underflow in tweetfinder's fire counter The commit adds a condition to avoid decrementing the fire counter when it's already at zero. This circumvents a potential underflow scenario in the windowlimiter logic of tweetfinder module, consequently enhancing system stability and dependability. --- internal/tweetfinder/windowlimiter/limiter.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/internal/tweetfinder/windowlimiter/limiter.go b/internal/tweetfinder/windowlimiter/limiter.go index 7847ee2..da21bf0 100644 --- a/internal/tweetfinder/windowlimiter/limiter.go +++ b/internal/tweetfinder/windowlimiter/limiter.go @@ -187,8 +187,9 @@ func (l *limiter) loop(ctx context.Context) { isError = false } case <-l.putOutFireTicker.C: - l.log.WithField(durationKey, l.duration).Debug("put out fire") if l.fire > 0 { + l.log.WithField(durationKey, l.duration).Debug("put out fire") + l.fire-- } case <-ticker.C: