Fix deep recursion in ResourceBasedSlotSupplier causing futures to never resolve#2779
Merged
tconley1428 merged 5 commits intomasterfrom Feb 11, 2026
Merged
Conversation
…ver resolve Replace recursive CompletableFuture chaining in scheduleSlotAcquisition with iterative polling approach using ScheduledExecutorService. The previous implementation created deep future chains that could cause stack overflow issues and prevent futures from completing when resources became available. Changes: - Replace thenCompose() chaining with scheduled polling task - Add proper cancellation handling with AtomicReference<ScheduledFuture<?>> - Maintain ramp throttle timing behavior - Add minimum 10ms delay to prevent tight spinning - Preserve all existing API contracts and behavior 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
mjameswh
reviewed
Feb 10, 2026
temporal-sdk/src/main/java/io/temporal/worker/tuning/ResourceBasedSlotSupplier.java
Outdated
Show resolved
Hide resolved
…github.com/temporalio/sdk-java into fix-resource-based-slot-supplier-recursion
mjameswh
approved these changes
Feb 10, 2026
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.
Summary
thenCompose()chaining with iterative polling usingScheduledExecutorServiceProblem
The previous implementation in
scheduleSlotAcquisition()used recursive CompletableFuture chaining that could create very deep call stacks. When resource starvation lasted for extended periods, this would result in chains of thousands of nested futures that would never resolve even after resources became available, due to stack depth issues and recursive completion problems.Solution
Replaced the recursive approach with:
ScheduledExecutorService.schedule()AtomicReference<ScheduledFuture<?>>Test Results
All tests in
ResourceBasedSlotSupplierNonRecursiveTestnow pass:testFutureNeverResolvesEvenAfterResourcesBecomeAvailable- FIXED: Future now completes in ~1-9ms instead of never completingtestFutureCancellationWithRecursiveChain- Proper cancellation still workstestMemoryAndPerformanceImpactOfDeepRecursion- Performance maintainedTest plan
ResourceBasedSlotSupplierNonRecursiveTest- all tests pass🤖 Generated with Claude Code