@@ -93,6 +93,7 @@ fn gcd(x: u64, y: u64) -> u64 {
9393pub struct TokenBucket {
9494 // Bucket defining traits.
9595 size : u64 ,
96+ // Initial burst size (number of free initial tokens, that can be consumed at no cost)
9697 one_time_burst : Option < u64 > ,
9798 // Complete refill time in milliseconds.
9899 refill_time : u64 ,
@@ -410,13 +411,12 @@ impl RateLimiter {
410411 ops_complete_refill_time_ms,
411412 ) ;
412413
413- // If limiting is disabled on all token types, don't even create a timer fd.
414- let timer_fd = if bytes_token_bucket. is_some ( ) || ops_token_bucket. is_some ( ) {
415- // create TimerFd using monotonic clock, as nonblocking FD and set close-on-exec
416- Some ( TimerFd :: new_custom ( ClockId :: Monotonic , true , true ) ?)
417- } else {
418- None
419- } ;
414+ // TODO: Self::timer_fd should not be an `Option` anymore; clean that up.
415+ //
416+ // We'll need a timer_fd, even if our current config effectively disables rate limiting,
417+ // because `Self::update_buckets()` might re-enable it later, and we might be
418+ // seccomp-blocked from creating the timer_fd at that time.
419+ let timer_fd = Some ( TimerFd :: new_custom ( ClockId :: Monotonic , true , true ) ?) ;
420420
421421 Ok ( RateLimiter {
422422 bandwidth : bytes_token_bucket,
@@ -509,7 +509,7 @@ impl RateLimiter {
509509 }
510510
511511 /// Updates the parameters of the token buckets associated with this RateLimiter.
512- // TODO: Pls note that, right now, the buckets buckets become full after being updated.
512+ // TODO: Pls note that, right now, the buckets become full after being updated.
513513 pub fn update_buckets ( & mut self , bytes : Option < TokenBucket > , ops : Option < TokenBucket > ) {
514514 // TODO: We have to call make_bucket instead of directly assigning the bytes and/or ops
515515 // because the input buckets are likely build via deserialization, which currently does not
@@ -673,8 +673,6 @@ mod tests {
673673 "SpuriousRateLimiterEvent(\
674674 \" Rate limiter event handler called without a present timer\" )"
675675 ) ;
676- // raw FD for this disabled rate-limiter should be -1
677- assert_eq ! ( l. as_raw_fd( ) , -1 ) ;
678676 }
679677
680678 #[ test]
0 commit comments