Balance throttle permits in SimpleAsyncTaskExecutor#36916
Open
junhyeong9812 wants to merge 2 commits into
Open
Balance throttle permits in SimpleAsyncTaskExecutor#36916junhyeong9812 wants to merge 2 commits into
junhyeong9812 wants to merge 2 commits into
Conversation
SimpleAsyncTaskExecutor.execute(Runnable, long) routed an immediate- timeout task through the active-thread tracking branch without acquiring a concurrency throttle permit, yet TaskTrackingRunnable.run() always released one via afterAccess(). With the throttle active and active-thread tracking enabled (a task termination timeout or cancel-on-close), each such task drove the concurrency count below zero, progressively defeating the configured concurrency limit. Track whether a permit was acquired and release it only in that case, so immediate-timeout tasks bypass the throttle entirely as documented. Signed-off-by: junhyeong9812 <pickjog@gmail.com>
A throttled task cancelled before it ran never released its acquired permit. Extend the try in TaskTrackingRunnable.run() to cover the cancellation check so a permit is always released once acquired. Rename the flag to releaseThrottle and make the throttle accounting tests deterministic. Signed-off-by: junhyeong9812 <pickjog@gmail.com>
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.
Overview
SimpleAsyncTaskExecutoracquires a concurrency throttle permit (beforeAccess()) only on thethrottled execution branch, but
TaskTrackingRunnable.run()released one (afterAccess())unconditionally. This unbalanced the throttle's concurrency count in two ways.
Problem
(
taskTerminationTimeout > 0orcancelRemainingTasksOnClose), an immediate-timeout task takesthe active-thread tracking branch without acquiring a permit, yet
run()still released one,driving the count below zero and progressively defeating the configured concurrency limit. This
is reachable through the deprecated
execute(Runnable, long)overload; the regularexecute(Runnable)/submit(...)paths useTIMEOUT_INDEFINITEand are unaffected.checkCancelled()threw ahead of the
try/finallyinrun()) never released its acquired permit.Fix
Track whether a permit was acquired and release it in
run()'sfinallyonly in that case, withthe
finallynow also coveringcheckCancelled(), so an acquired permit is always releasedexactly once. Deterministic regression tests are added to
SimpleAsyncTaskExecutorTests.