Implement Automatic Subscription Cleanup with Client Lifecycle Tracking#686
Open
Implement Automatic Subscription Cleanup with Client Lifecycle Tracking#686
Conversation
bc6b1f4 to
3aec7f5
Compare
3aec7f5 to
cb4c78a
Compare
- Add SubscriptionHolder class with reference counting - Add SubscriptionCleanup interface for cleanup operations - Update GenericIngressSubscription with reference counting support - Fix validateErigonBug typo in ChainOptions and EthereumChainSpecific - Add proper cleanup mechanism for WebSocket subscriptions
- Add SubscriptionClient interface for client identification - Create DefaultSubscriptionClient with disconnect callbacks - Add ClientAwareSubscriptionConnect wrapper for tracking client lifecycle - Update SubscriptionHolder to track individual clients instead of ref counting - Implement automatic cleanup when clients disconnect - Add client ID generation for unique client identification
…ription Add client tracking and auto-cleanup capabilities to EthereumWsIngressSubscription: - Integrate with SubscriptionHolder and DefaultSubscriptionClient for lifecycle tracking - Add cleanup logic with proper eth_unsubscribe calls - Add subscription statistics and monitoring capabilities - Implement proper client reference counting to trigger cleanup when last client disconnects This establishes the foundation for Ethereum subscription auto-cleanup similar to other blockchain implementations.
Create EthereumSubscriptionConnect class for client-tracked Ethereum subscriptions: - Support for newHeads, logs, and pendingTransactions via eth_subscribe/eth_unsubscribe - Integrate with GenericPersistentConnect pattern for automatic cleanup - Expand EthereumWsIngressSubscription to handle all Ethereum subscription types - Add proper parameter handling for different subscription methods (logs with filters, etc.) - Maintain subscription ID tracking for cleanup coordination This provides the connection infrastructure needed for Ethereum subscription auto-cleanup.
Wire EthereumEgressSubscription to use EthereumWsIngressSubscription for auto-cleanup: - Add IngressSubscription parameter to EthereumEgressSubscription constructor - Route subscription requests through client-tracked IngressSubscription when available - Fall back to direct connections for backward compatibility (legacy mode) - Update EthereumChainSpecific to wire IngressSubscription to EgressSubscription - Add backward compatible constructor to maintain test compatibility - Log mode (client-tracked vs legacy) for debugging This completes the integration allowing Ethereum subscriptions to benefit from automatic cleanup when clients disconnect.
- Test EthereumWsIngressSubscription client tracking and cleanup logic - Verify multiple clients can share same subscription with proper reference counting - Test automatic cleanup when last client disconnects - Verify eth_unsubscribe is called on subscription cleanup - Test different subscription topics are handled independently - Confirm unique client ID generation and subscription statistics These tests validate the core auto-cleanup functionality works correctly for Ethereum subscriptions.
cb4c78a to
cd1580c
Compare
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.
Problem Solved
Previously, WebSocket subscriptions in Dshackle lacked proper cleanup mechanisms, leading to potential memory leaks and resource waste. When clients disconnected, subscriptions would remain active upstream even when no longer needed, causing:
New Architecture Overview
This PR introduces a comprehensive client lifecycle tracking system for WebSocket subscriptions with automatic cleanup:
Phase 1: Reference Counting Infrastructure
Phase 2: Client Lifecycle Tracking
Phase 3: Comprehensive Testing
Key Features
Implementation Details