{"record":{"id":"b1487a8a3bfa4d1e","repo":"nautechsystems/nautilus_trader","slug":"rpc-block-feed-active-without-an-rpc-client","errorCode":null,"errorMessage":"RPC block feed active without an RPC client","messagePattern":"RPC block feed active without an RPC client","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/blockchain/src/data/client.rs","lineNumber":1103,"sourceCode":"        core_client\n            .subscription_manager\n            .block_feed_started(started_backend);\n        Ok(())\n    }\n\n    async fn unsubscribe_block_feed(\n        core_client: &mut BlockchainDataClientCore,\n        owner: BlockFeedOwner,\n    ) -> anyhow::Result<()> {\n        let Some(backend) = core_client.subscription_manager.remove_block_demand(owner) else {\n            log::debug!(\"Keeping block subscription active while another owner remains\");\n            return Ok(());\n        };\n\n        match backend {\n            BlockFeedBackend::Rpc => {\n                let Some(rpc) = core_client.rpc_client.as_mut() else {\n                    anyhow::bail!(\"RPC block feed active without an RPC client\")\n                };\n                rpc.unsubscribe_blocks().await?;\n                log::debug!(\"Unsubscribed from blocks via RPC\");\n            }\n            BlockFeedBackend::HyperSync => {\n                core_client.hypersync_client.unsubscribe_blocks().await;\n                log::debug!(\"Unsubscribed from blocks via HyperSync\");\n            }\n        }\n\n        core_client.subscription_manager.block_feed_stopped(backend);\n        Ok(())\n    }\n\n    /// Processes DeFi request commands to fetch specific blockchain data.\n    async fn handle_request_command(\n        command: DefiRequestCommand,\n        core_client: &mut BlockchainDataClientCore,","sourceCodeStart":1085,"sourceCodeEnd":1121,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/blockchain/src/data/client.rs#L1085-L1121","documentation":"unsubscribe_block_feed sees an active RPC block feed backend but the core client's rpc_client is None, which is an inconsistent state — a live RPC subscription exists without the client that owns it. It bails rather than silently skipping cleanup.","triggerScenarios":"Calling unsubscribe_block_feed when the tracked backend is BlockFeedBackend::Rpc but the client was rebuilt/reconnected without rpc_client, or the backend record was set to Rpc while rpc_client was dropped.","commonSituations":"Client re-initialization between subscribe and unsubscribe; mixing backend configurations across reconnects; internal state corruption after an RPC client teardown.","solutions":["Ensure the same client instance/config that subscribed (with rpc_client present) performs the unsubscribe","Re-initialize the RPC client before unsubscribing","If switching backends intentionally, unsubscribe with the correct backend selection"],"exampleFix":"// before\n// client recreated without rpc url; unsubscribe_block_feed() fails\n// after\nclient.reconnect_with_rpc(\"wss://...\")?; // restores rpc_client\nclient.unsubscribe_block_feed().await?;","handlingStrategy":"type-guard","validationCode":"if backend == BlockFeedBackend::Rpc && client.rpc_client().is_none() {\n    log::warn!(\"rpc client gone; skipping rpc block unsubscribe\");\n    return;\n}","typeGuard":"fn rpc_available(c: &BlockchainDataClient) -> bool { c.core.rpc_client.is_some() }","tryCatchPattern":"match client.unsubscribe_block_feed().await {\n    Err(e) if e.to_string().contains(\"active without an RPC client\") => {\n        log::warn!(\"stale rpc backend state; resetting block feed state\");\n    }\n    r => r?,\n}","preventionTips":["Keep backend state and rpc_client lifecycle in sync (reset backend when rpc_client drops)","Rebuild the client fully rather than partially on reconnect","Log backend transitions to catch divergence early"],"tags":["rpc","block-feed","state","unsubscribe"],"backgroundTag":"internal-invariant-violation","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}