Fix task queue rate-limit for invalid tasks#7590
Merged
Conversation
Signed-off-by: Carly de Frondeville <carly.defrondeville@temporal.io>
yiminc
reviewed
Apr 8, 2025
prathyushpv
reviewed
Apr 9, 2025
prathyushpv
approved these changes
Apr 11, 2025
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.
What changed?
Implement
RecycleTokeninMultiRateLimiterand add functional tests.Why?
ClockedRateLimiteris the base rate limiter for many rate limiters in our system, so I made the mistake of assuming that implementingRecycleTokenthere and and then callingClockedRateLimiter.RecycleTokenfrom other wrapper rate limiters (such asMultiRateLimiterandDynamicRateLimiter) would "just work."However, a limitation of the recycle token implementation is that another process must be waiting on a token (via
ClockedRateLimiter.Wait) at the time whenRecycleTokenis called.DynamicRateLimiter.WaitcallsClockedRateLimiter.Wait, which means thatDynamicRateLimiter.RecycleTokencan simply callClockedRateLimiter.RecycleToken.However,
MultiRateLimiter.Waitdoes not call theWaitmethod of its sub-rate-limiters; instead it implements a customWaitmethod using theReservemethods of its sub-rate-limiters. This means the sub-rate-limiters never callWaitand never wait for the recycled token to arrive. GivingMultiRateLimitera customRecycleTokenimplementation that pairs with the customMultiRateLimiter.Waitsolves this problem.How did you test it?
Tested in a test server using sample workflows, and with functional tests for old and new matcher.
Note that New Matcher did not have this bug, because it does not use
MultiRateLimiterfor task queue rate limiting.Potential risks
Documentation
Is hotfix candidate?
It fixes a bug, but the bug only occurs when many workflows that have backlogged tasks become invalid (ie. via termination or deletion).