From e85d8b9a77d79be3f7defdaa7d99bfa93aae0e11 Mon Sep 17 00:00:00 2001 From: Dan Kortschak <90160302+efd6@users.noreply.github.com> Date: Wed, 29 Jun 2022 19:19:17 +0930 Subject: [PATCH] x-pack/filebeat/input/httpjson: use timer instead of ticker for singleshot (#32061) --- x-pack/filebeat/input/httpjson/rate_limiter.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/x-pack/filebeat/input/httpjson/rate_limiter.go b/x-pack/filebeat/input/httpjson/rate_limiter.go index 7e86af88900..dd8c2298086 100644 --- a/x-pack/filebeat/input/httpjson/rate_limiter.go +++ b/x-pack/filebeat/input/httpjson/rate_limiter.go @@ -77,14 +77,15 @@ func (r *rateLimiter) applyRateLimit(ctx context.Context, resp *http.Response) e return nil } r.log.Debugf("Rate Limit: Wait until %v for the rate limit to reset.", t) - ticker := time.NewTicker(w) - defer ticker.Stop() - + timer := time.NewTimer(w) select { case <-ctx.Done(): + if !timer.Stop() { + <-timer.C + } r.log.Info("Context done.") return nil - case <-ticker.C: + case <-timer.C: r.log.Debug("Rate Limit: time is up.") return nil }