RDKEMW-21222: Implement connection-level and session-level cleanup mechanisms#949
Conversation
…chanisms - Add CleanupType enum with Connection(cid) and Session(session_id) variants - Update BrokerCleaner with cleanup_connection() and cleanup_session() methods - Add cleanup_for_connection() for WebSocket disconnect (cleans only that connection) - Add cleanup_for_session() for app unload (cleans ALL subscriptions for session) - Update subscription_map to use cid as key when available via get_subscription_key() - Wire session cleanup in end_session() in delegated_launcher_handler - Remove unused cleanup_for_app() and UnloadSession command - Add unit tests for cleanup functionality
…ure mode - Remove redundant AppEvents::remove_session(session_id) call from disconnect handler - Add comprehensive unit test test_cleanup_by_connection_id_shared_session_multi_connection to verify multi-connection shared session scenario and prevent regression. This prevents correctness bugs in secure connection mode where multiple clients share the same logical session.
…ion requests - Log 'Sending Thunder register for <plugin>.<event>' when subscribing to Thunder events - Log 'Sending Thunder unregister for <plugin>.<event>' when unsubscribing from Thunder events - These logs enable runtime monitoring of subscription lifecycle for debugging memory leaks - Example: 'Sending Thunder unregister for org.rdk.TextToSpeech.onnetworkerror'
There was a problem hiding this comment.
Pull request overview
This PR introduces distinct cleanup paths for WebSocket-connection disconnects vs app-session termination, aiming to prevent over-cleaning in secure-mode scenarios where multiple connections share a session.
Changes:
- Add connection-level vs session-level cleanup semantics via a new
CleanupTypeand newcleanup_for_connection/cleanup_for_sessionAPIs. - Update disconnect handling to clean listeners/subscriptions by connection id (cid) instead of session id.
- Extend/adjust tests to validate correct listener cleanup in shared-session multi-connection scenarios.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| core/main/src/service/apps/delegated_launcher_handler.rs | Adds session-level endpoint cleanup on app session end. |
| core/main/src/service/apps/app_events.rs | Adds a regression test ensuring cid-based cleanup doesn’t remove other connections in the same session. |
| core/main/src/firebolt/firebolt_gateway.rs | Switches disconnect cleanup to cid-based listener + broker subscription cleanup. |
| core/main/src/broker/websocket_broker.rs | Updates cleaner channel to use CleanupType for cleanup signaling. |
| core/main/src/broker/thunder_broker.rs | Implements cid-based and session-based broker subscription cleanup logic; adjusts subscription keying behavior. |
| core/main/src/broker/endpoint_broker.rs | Introduces CleanupType, adds connection/session cleanup APIs, and updates tests accordingly. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Remove DeviceEvent::Cleanup enum variant from device_events.rs - Remove Cleanup handling from thunder_events.rs processor - Remove Cleanup handling from thunder_event_processor.rs - Remove cleanup dispatch from firebolt_gateway.rs - Remove related unit tests (test_cleanup_event_request_payload_roundtrip, test_cleanup_event_contract) - Remove unused 'log::info' import Note: Connection-level cleanup via cleanup_for_connection() remains and handles all necessary broker-layer subscription cleanup. This is sufficient for proper system cleanup without requiring the extension layer cleanup.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (1)
core/main/src/broker/service_broker.rs:26
trace!is imported fromjsonrpsee::tracing, while the rest of this broker uses theripple_sdk::logfacade (error!/info!). This mixes two logging backends and can cause the new trace log to be dropped or configured differently than other broker logs. Prefer usingripple_sdk::log::tracefor consistency across the codebase.
use crate::state::platform_state::PlatformState;
use jsonrpsee::tracing::trace;
use ripple_sdk::{
api::{gateway::rpc_gateway_api::JsonRpcApiError, observability::log_signal::LogSignal},
log::{error, info},
service::service_message::{Id, ServiceMessage},
Use cid (connection_id) as storage key with fallback to session_id, matching Thunder broker pattern. This ensures cleanup_for_connection(cid) can properly close brokers when WebSocket disconnects.
Only re-insert Vec into subscription_map if it's non-empty after removing matching subscription. This prevents map bloat from accumulating empty entries when requests with listen=false remove the last subscription for a key, avoiding unnecessary memory usage and cleanup iterations.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.
Comments suppressed due to low confidence (1)
core/main/src/broker/service_broker.rs:26
ServiceBrokerimportstracefromjsonrpsee::tracing, but the rest of this crate appears to consistently use theripple_sdk::logmacros (e.g., many files importlog::{..., trace}). Mixing logging frameworks can lead to inconsistent filtering/formatting. Prefer usingripple_sdk::log::tracehere as well.
use jsonrpsee::tracing::trace;
use ripple_sdk::{
api::{gateway::rpc_gateway_api::JsonRpcApiError, observability::log_signal::LogSignal},
log::{error, info},
service::service_message::{Id, ServiceMessage},
Minimum allowed line rate is |
What
What does this PR add or remove?
Why
Why are these changes needed?
How
How do these changes achieve the goal?
Test
How has this been tested? How can a reviewer test it?
Checklist