fix(foundation): add TTL expiry and cancel_request to DeferredQueue to prevent memory leaks#1578
Open
SH20RAJ wants to merge 1 commit intomofa-org:mainfrom
Open
fix(foundation): add TTL expiry and cancel_request to DeferredQueue to prevent memory leaks#1578SH20RAJ wants to merge 1 commit intomofa-org:mainfrom
SH20RAJ wants to merge 1 commit intomofa-org:mainfrom
Conversation
…o prevent memory leaks (mofa-org#1569)
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
Fixes #1569 - DeferredQueue was leaking requests on client disconnection, filling up the queue with "ghost" requests and preventing new legitimate requests from being enqueued.
Problem
The DeferredQueue had no mechanism to:
Scenario
Expected: New request accepted or enqueued
Actual: Rejected because queue full of "ghost" requests
Solution
1. TTL-Based Expiry (default 5 minutes)
Added to DeferredRequest:
Requests automatically expire after TTL, preventing indefinite accumulation.
2. Explicit Cancellation
Added to DeferredQueue:
Orchestration layer or scheduler can cancel specific requests when callers disconnect.
3. Updated Dequeue Logic
dequeue_oldest_fitting()drain_ttl_expired()method for background cleanup4. Comprehensive Tests
test_cancel_request()- cancel and verify removaltest_ttl_expiry()- requests expire after TTLtest_drain_ttl_expired()- background TTL cleanuptest_ghost_request_prevention()- full scenario fixImpact
✅ Prevents DoS via filled queue from disconnected callers
✅ Automatic cleanup without manual intervention
✅ Graceful support for both explicit + automatic expiry
✅ Backward compatible (default TTL = 5 min)
Testing
All new tests pass. Backwards compatible with existing code.
GSOC 2026 Contribution
Addresses critical P1 issue #1569. Demonstrates:
Cc: @Mustafa11300 @rahulkr182