Skip to content

Fix deep recursion in ResourceBasedSlotSupplier causing futures to never resolve#2779

Merged
tconley1428 merged 5 commits intomasterfrom
fix-resource-based-slot-supplier-recursion
Feb 11, 2026
Merged

Fix deep recursion in ResourceBasedSlotSupplier causing futures to never resolve#2779
tconley1428 merged 5 commits intomasterfrom
fix-resource-based-slot-supplier-recursion

Conversation

@tconley1428
Copy link
Contributor

Summary

  • Fixed a critical bug where ResourceBasedSlotSupplier futures would never complete due to deep recursion in CompletableFuture chains
  • Replaced recursive thenCompose() chaining with iterative polling using ScheduledExecutorService
  • Added comprehensive test suite to verify the fix and prevent regressions

Problem

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:

  1. Iterative polling mechanism using ScheduledExecutorService.schedule()
  2. Proper cancellation handling with AtomicReference<ScheduledFuture<?>>
  3. Maintained timing contracts - still respects ramp throttle delays
  4. Added minimum 10ms delay to prevent tight spinning
  5. Preserved all existing API behavior and contracts

Test Results

All tests in ResourceBasedSlotSupplierNonRecursiveTest now pass:

  • testFutureNeverResolvesEvenAfterResourcesBecomeAvailable - FIXED: Future now completes in ~1-9ms instead of never completing
  • testFutureCancellationWithRecursiveChain - Proper cancellation still works
  • testMemoryAndPerformanceImpactOfDeepRecursion - Performance maintained
  • ✅ All other existing behavior preserved

Test plan

  • Run ResourceBasedSlotSupplierNonRecursiveTest - all tests pass
  • Verify the main bug fix: futures complete immediately when resources become available
  • Verify no regressions in cancellation, memory usage, or timing behavior
  • Code compiles and builds successfully

🤖 Generated with Claude Code

…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>
@tconley1428 tconley1428 requested a review from a team as a code owner February 9, 2026 21:23
@tconley1428 tconley1428 merged commit 22a1c1a into master Feb 11, 2026
34 of 37 checks passed
@tconley1428 tconley1428 deleted the fix-resource-based-slot-supplier-recursion branch February 11, 2026 16:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants