Respect CancellationToken in AcquireAsyncCore before dispatching - #264
Open
anasik wants to merge 1 commit into
Open
Respect CancellationToken in AcquireAsyncCore before dispatching#264anasik wants to merge 1 commit into
anasik wants to merge 1 commit into
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #263.
RedisSlidingWindowRateLimiter,RedisFixedWindowRateLimiter, andRedisTokenBucketRateLimiterall accept aCancellationTokeninAcquireAsyncCorebut never check it before issuing the underlying Redis command —RedisConcurrencyRateLimiteris the only one that already observes cancellation (via a registered callback), so this brings the other three in line with that existing pattern.StackExchange.Redishas 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.