Repository navigation
Conversation
…ume (#6645) onErrorResume absorbed every Redis error into a normal Flux.just(1L, -1L) emission, so the trailing doOnError (which logged the error and invoked the rate limiter algorithm's callback, e.g. cleanup of optimistically written keys) was unreachable dead code. On a Redis outage every request was silently fail-opened with no log signal and no cleanup callback. Move the callback invocation and error logging into the onErrorResume lambda itself so they actually execute when Redis errors occur.
There was a problem hiding this comment.
🟡 Changes recommended
The new error-path logging drops the Throwable stack trace and the callback invocation isn’t guarded, which can undermine debuggability and potentially break the intended fail-open behavior if the callback throws.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Fixes a bug in the rate limiter’s Redis error handling where Redis failures were being absorbed by onErrorResume, making downstream .doOnError(...) logging and algorithm cleanup callbacks unreachable (silent fail-open with no cleanup signal).
Changes:
- Moves rate-limiter algorithm callback invocation and error logging into the
onErrorResumeerror handler inRedisRateLimiter.isAllowed. - Removes the now-dead downstream
.doOnError(...)block. - Adds a unit test asserting the concurrent algorithm’s error callback (Redis ZSET cleanup) is invoked when the Redis script execution errors.
File summaries
| File | Description |
|---|---|
| shenyu-plugin/shenyu-plugin-fault-tolerance/shenyu-plugin-ratelimiter/src/main/java/org/apache/shenyu/plugin/ratelimiter/executor/RedisRateLimiter.java | Ensures algorithm callback + logging occur on Redis errors by executing them inside onErrorResume, fixing previously unreachable error side-effects. |
| shenyu-plugin/shenyu-plugin-fault-tolerance/shenyu-plugin-ratelimiter/src/test/java/org/apache/shenyu/plugin/ratelimiter/executor/RedisRateLimiterTest.java | Adds a regression test confirming the concurrent algorithm cleanup callback is invoked on Redis execution failure. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
Aias00
left a comment
There was a problem hiding this comment.
Thanks @dmsolr!
The root-cause analysis is correct: onErrorResume absorbs the Redis error before it can reach the trailing .doOnError(...), so the algorithm callback and error logging were unreachable dead code — on a Redis outage every request silently fail-opened.
The fix is sound:
- Moving
rateLimiterAlgorithm.callback(script, keys, scriptArgs)and the error log into theonErrorResumelambda makes both actually execute; the argument is equivalent to the oldrateLimiterAlgorithm.getScript(). - Wrapping the callback in try/catch is a good defensive addition — a callback failure (e.g. Redis still down during zset cleanup) can no longer break the fallback emission.
- Fail-open semantics (
allowed=true, tokensRemaining=-1) are unchanged, so this is purely a correctness/observability fix with no behavioral regression. - The new test
allowedThrowableInvokesAlgorithmCallbackTestfails on the old code and passes on the new one, and its mocks matchConcurrentRateLimiterAlgorithm#callback(which callsopsForZSet().remove(...).subscribe()— the mock interaction is recorded synchronously, soverifyis reliable).
LGTM, approving.
…ume (apache#6645) (apache#7029) * fix: invoke RedisRateLimiter error callback/logging inside onErrorResume (apache#6645) onErrorResume absorbed every Redis error into a normal Flux.just(1L, -1L) emission, so the trailing doOnError (which logged the error and invoked the rate limiter algorithm's callback, e.g. cleanup of optimistically written keys) was unreachable dead code. On a Redis outage every request was silently fail-opened with no log signal and no cleanup callback. Move the callback invocation and error logging into the onErrorResume lambda itself so they actually execute when Redis errors occur. * Improve error handling in RedisRateLimiter Co-authored-by: Copilot Autofix powered by AI <[email protected]> --------- Co-authored-by: Luke Haochao Zhuang <[email protected]> Co-authored-by: Copilot Autofix powered by AI <[email protected]> Co-authored-by: aias00 <[email protected]>
Fixes #6645
Root cause
In
RedisRateLimiter.isAllowed,onErrorResumeabsorbed every Redis error into a normalFlux.just(1L, -1L)emission, so the trailing.doOnError(...)(which logged the error and invoked the rate limiter algorithm'scallback, e.g. cleanup of optimistically-written keys inConcurrentRateLimiterAlgorithm) was unreachable dead code. On a Redis outage, every request was silently fail-opened with no log signal and no cleanup callback.Fix
Move the algorithm callback invocation and error logging into the
onErrorResumelambda itself, so they actually execute when a Redis error occurs. Removed the now-dead.doOnError(...).Testing
Added
allowedThrowableInvokesAlgorithmCallbackTestinRedisRateLimiterTest, using theconcurrentalgorithm, asserting the algorithm's error callback (Redis zset cleanup) is invoked when the Redis call errors. This test fails against the old code and passes after the fix../mvnw -pl shenyu-plugin/shenyu-plugin-fault-tolerance/shenyu-plugin-ratelimiter -am test: checkstyle 0 violations, full reactor build success, all tests pass (including 8/8 inRedisRateLimiterTest).You have read the contribution guidelines.
You submit test cases (unit or integration tests) that back your changes.
Your local test passed
./mvnw clean install -Dmaven.javadoc.skip=true(module-scoped).