{"record":{"id":"cd0ec8084ecb5f06","repo":"nautechsystems/nautilus_trader","slug":"failed-to-send-updateassetcontextsubs-command-e","errorCode":null,"errorMessage":"Failed to send UpdateAssetContextSubs command: {e}","messagePattern":"Failed to send UpdateAssetContextSubs command: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/hyperliquid/src/websocket/client.rs","lineNumber":2003,"sourceCode":"        instrument_id: InstrumentId,\n        data_type: AssetContextDataType,\n    ) -> anyhow::Result<()> {\n        let instrument = self\n            .get_instrument(&instrument_id)\n            .ok_or_else(|| InstrumentLookupError::not_found(instrument_id))?;\n        let coin = instrument.raw_symbol().inner();\n\n        let mut entry = self.asset_context_subs.entry(coin).or_default();\n        let is_first_subscription = entry.is_empty();\n        entry.insert(data_type);\n        let data_types = entry.clone();\n        drop(entry);\n\n        let cmd_tx = self.cmd_tx.read().await;\n\n        cmd_tx\n            .send(HandlerCommand::UpdateAssetContextSubs { coin, data_types })\n            .map_err(|e| anyhow::anyhow!(\"Failed to send UpdateAssetContextSubs command: {e}\"))?;\n\n        if is_first_subscription {\n            log::debug!(\n                \"First asset context subscription for coin '{coin}', subscribing to ActiveAssetCtx\"\n            );\n            let subscription = SubscriptionRequest::ActiveAssetCtx { coin };\n\n            cmd_tx\n                .send(HandlerCommand::UpdateInstrument(instrument.clone()))\n                .map_err(|e| anyhow::anyhow!(\"Failed to send UpdateInstrument command: {e}\"))?;\n\n            if let Err(e) = self.send_subscription(&cmd_tx, subscription) {\n                if let Some(mut entry) = self.asset_context_subs.get_mut(&coin) {\n                    entry.remove(&data_type);\n                    let rollback = entry.clone();\n                    let remove_entry = entry.is_empty();\n                    drop(entry);\n","sourceCodeStart":1985,"sourceCodeEnd":2021,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/hyperliquid/src/websocket/client.rs#L1985-L2021","documentation":"This error is raised when the Hyperliquid WebSocket client cannot forward an UpdateAssetContextSubs HandlerCommand to its internal handler task over the command channel. It means the command mpsc channel is closed or the receiver was dropped, i.e. the handler task is no longer running. It is a wrapper around the underlying SendError, not a Hyperliquid exchange error.","triggerScenarios":"Calling subscribe (or the asset-context subscription path) after the WebSocket handler task has terminated, e.g. after disconnect without reconnect, or calling before the client's handler task was ever started. cmd_tx.send returns Err and the anyhow wrapper adds this message.","commonSituations":"Reusing a client after connection teardown; a race where the handler task crashed (panic or network shutdown) while subscription logic still runs; calling subscribe concurrently with close(); keeping a stale client handle in long-lived services.","solutions":["Reconnect the WebSocket client before subscribing; check connection state first","Verify the client was connected and started before calling subscribe","Treat this as a terminal client state: recreate the client instance","Inspect logs for a prior handler-task panic that closed the command channel"],"exampleFix":"// before\nclient.subscribe(data_type).await?;\n// after\nif !client.is_connected() {\n    client.connect().await?;\n}\nclient.subscribe(data_type).await?;","handlingStrategy":"try-catch","validationCode":"// Rust\nfn can_subscribe(client: &HyperliquidWsClient) -> bool {\n    client.is_connected()\n}","typeGuard":null,"tryCatchPattern":"match client.subscribe(data_type).await {\n    Ok(()) => {},\n    Err(e) if e.to_string().contains(\"Failed to send\") => {\n        client.connect().await?;\n        client.subscribe(data_type).await?;\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Always connect the client before subscribing","Avoid calling subscribe after close()/drop of the client","Monitor handler task health and reconnect on disconnect events","Centralize subscribe calls behind a helper that checks connection state"],"tags":["websocket","channel-closed","rust","hyperliquid"],"backgroundTag":"broken-pipe","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"}