Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Intermittent Failed to acquire key Errors in Concurrent RateLimiter Usage with FakeRelativeClock #254

Open
NOBLES5E opened this issue Jan 11, 2025 · 0 comments

Comments

@NOBLES5E
Copy link

NOBLES5E commented Jan 11, 2025

Test Code:

Repo here: https://github.com/NOBLES5E/governor-bug

fn main() {
    let clock = FakeRelativeClock::default();
    let quota = Quota::per_second(nonzero!(2500u32));
    let lim = Arc::new(RateLimiter::hashmap_with_clock(quota, clock));
    let ms = Duration::from_millis(1);
    let key = Bytes::from("conflict_key");

    crossbeam::scope(|scope| {
        for _ in 0..10 {
            let key = key.clone();
            let lim = lim.clone();
            scope.spawn(move |_| {
                for _ in 0..250 {
                    let ret = lim.check_key(&key).expect("Failed to acquire key");
                    lim.clock().advance(100 * ms);
                }
            });
        }
    })
    .unwrap();
}

Observed Behavior:
Occasionally, the test fails with an error similar to:

Failed to acquire key: NotUntil { state: StateSnapshot { t: Nanos(400µs), tau: Nanos(999.6ms), time_of_measurement: Nanos(60.5008s), tat: Nanos(60.5008s) }, start: Nanos(0ns) }

Check https://github.com/NOBLES5E/governor-bug/actions/runs/12728781775/job/35479772416 for example.

Expected Behavior:
Given the rate limiter is configured with a quota of 2500 requests per second and each thread performs 250 requests with a total simulated time advancement that should comfortably accommodate the quota, the check_key method should not fail.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant