{"record":{"id":"caaac1aecf947fd0","repo":"nautechsystems/nautilus_trader","slug":"failed-to-send-setdepth10sub-command-e","errorCode":null,"errorMessage":"Failed to send SetDepth10Sub command: {e}","messagePattern":"Failed to send SetDepth10Sub command: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/hyperliquid/src/websocket/client.rs","lineNumber":1405,"sourceCode":"        mantissa: Option<u32>,\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 cmd_tx = self.cmd_tx.read().await;\n\n        cmd_tx\n            .send(HandlerCommand::UpdateInstrument(instrument.clone()))\n            .map_err(|e| anyhow::anyhow!(\"Failed to send UpdateInstrument command: {e}\"))?;\n\n        cmd_tx\n            .send(HandlerCommand::SetDepth10Sub {\n                coin,\n                subscribed: true,\n            })\n            .map_err(|e| anyhow::anyhow!(\"Failed to send SetDepth10Sub command: {e}\"))?;\n\n        self.send_book_stream_subscribe(&cmd_tx, coin, BookStreamUse::Depth10, n_sig_figs, mantissa)\n    }\n\n    /// Unsubscribe from order book depth-10 snapshots.\n    ///\n    /// Clears the depth10 emission flag and tears down the underlying\n    /// `l2Book` stream unless active deltas subscribers still need it.\n    pub async fn unsubscribe_book_depth10(\n        &self,\n        instrument_id: InstrumentId,\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 cmd_tx = self.cmd_tx.read().await;","sourceCodeStart":1387,"sourceCodeEnd":1423,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/hyperliquid/src/websocket/client.rs#L1387-L1423","documentation":"This error wraps a failed send of the SetDepth10Sub(subscribed: true) command on the client's internal mpsc command channel. It is thrown right after the UpdateInstrument registration during depth-10 subscription, so the handler task stopped accepting commands between the two sends. It indicates the WebSocket handler receiver is closed.","triggerScenarios":"Calling subscribe_book_depth10 when the handler task has already terminated — after disconnect(), after the handler task panicked or its JoinHandle/receiver was dropped, or on a client whose run loop exited between the preceding UpdateInstrument send and this one.","commonSituations":"Subscribe racing with shutdown/disconnect; handler task crashed earlier (check its logs); client used after being moved into a scope that ended; runtime shutdown during teardown.","solutions":["Verify the handler task is alive (JoinHandle not finished) before subscribing; respawn/reconnect if it exited.","Avoid calling subscribe concurrently with disconnect/shutdown; sequence them or guard with application-level state.","Re-create the client if the handler loop exited; the channel cannot be revived.","Check handler-task logs/panic hooks for the root cause of the loop exiting."],"exampleFix":"// before\nclient.disconnect().await?;\nclient.subscribe_book_depth10(instrument_id).await?; // channel already closed\n\n// after\nif !client.is_connected() {\n    client.connect().await?;\n}\nclient.subscribe_book_depth10(instrument_id).await?;","handlingStrategy":"try-catch","validationCode":"// rust\nif !client.is_connected() {\n    return Err(anyhow::anyhow!(\"client not connected before depth10 subscribe\"));\n}","typeGuard":null,"tryCatchPattern":"// rust\nif let Err(e) = client.subscribe_book_depth10(instrument_id).await {\n    if e.to_string().contains(\"SetDepth10Sub\") {\n        tracing::warn!(\"handler channel closed ({e}); re-establishing client\");\n        client = reconnect_client().await?;\n        client.subscribe_book_depth10(instrument_id).await?;\n    } else { return Err(e); }\n}","preventionTips":["Keep the handler task running until all subscriptions are torn down.","Avoid racing subscribe with disconnect/shutdown; use a connection-state guard.","Log handler task completion (JoinHandle await) to detect premature exit.","Re-create the client after any handler-channel failure; never reuse it."],"tags":["rust","tokio","websocket","channel-closed","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-14T00:17:10.932Z"}