Skip to content

Respect CancellationToken in AcquireAsyncCore before dispatching - #264

Open
anasik wants to merge 1 commit into
cristipufu:masterfrom
anasik:fix/respect-cancellation-token
Open

Respect CancellationToken in AcquireAsyncCore before dispatching#264
anasik wants to merge 1 commit into
cristipufu:masterfrom
anasik:fix/respect-cancellation-token

Conversation

@anasik

@anasik anasik commented Aug 15, 2026

Copy link
Copy Markdown

Fixes #263.

RedisSlidingWindowRateLimiter, RedisFixedWindowRateLimiter, and RedisTokenBucketRateLimiter all accept a CancellationToken in AcquireAsyncCore but never check it before issuing the underlying Redis command — RedisConcurrencyRateLimiter is the only one that already observes cancellation (via a registered callback), so this brings the other three in line with that existing pattern.

StackExchange.Redis has no true mid-flight cancellation for an already-dispatched command, so this can't abort a call that's already in flight — but it does let a caller's cancellation take effect before a new call is dispatched, rather than silently ignoring the token altogether.

Minimal, additive change: one cancellationToken.ThrowIfCancellationRequested() per affected limiter, placed after the existing permit-count validation and before the Redis call is issued. No behavior change when the token isn't cancelled.

RedisSlidingWindowRateLimiter, RedisFixedWindowRateLimiter, and
RedisTokenBucketRateLimiter all accept a CancellationToken in
AcquireAsyncCore but never check it before issuing the underlying
Redis command, unlike RedisConcurrencyRateLimiter which already
observes cancellation via a registered callback.

StackExchange.Redis has no true mid-flight cancellation for an
already-dispatched command, so this can't stop a call that's already
in flight, but it does let a caller's cancellation take effect before
a new call is dispatched, and makes the previously-ignored parameter
actually mean something.

Fixes cristipufu#263
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

Successfully merging this pull request may close these issues.

RedisSlidingWindowRateLimiter.AcquireAsyncCore ignores the CancellationToken parameter

1 participant