Skip to content

Commit

Permalink
x-pack/filebeat/input/httpjson: use timer instead of ticker for singl…
Browse files Browse the repository at this point in the history
…eshot (#32061)
  • Loading branch information
efd6 authored Jun 29, 2022
1 parent bbd1c9b commit e85d8b9
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions x-pack/filebeat/input/httpjson/rate_limiter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit e85d8b9

Please sign in to comment.