{"record":{"id":"e3555dafc4d8f803","repo":"nautechsystems/nautilus_trader","slug":"failed-to-send-resubscribe-command-e","errorCode":null,"errorMessage":"Failed to send resubscribe command: {e}","messagePattern":"Failed to send resubscribe command: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/hyperliquid/src/websocket/client.rs","lineNumber":1864,"sourceCode":"        // Keep the registration check atomic with the resubscribe pair\n        let cmd_tx = self.cmd_tx.write().await;\n\n        if !self.quote_streams.contains_key(&coin) {\n            log::debug!(\"Skipping bbo resubscribe for {coin}: stream no longer registered\");\n            return Ok(());\n        }\n\n        self.send_stream_resubscribe(&cmd_tx, SubscriptionRequest::Bbo { coin })\n    }\n\n    fn send_stream_resubscribe(\n        &self,\n        cmd_tx: &tokio::sync::mpsc::UnboundedSender<HandlerCommand>,\n        subscription: SubscriptionRequest,\n    ) -> anyhow::Result<()> {\n        cmd_tx\n            .send(HandlerCommand::Resubscribe { subscription })\n            .map_err(|e| anyhow::anyhow!(\"Failed to send resubscribe command: {e}\"))\n    }\n\n    /// Unsubscribe from trades for an instrument.\n    pub async fn unsubscribe_trades(&self, instrument_id: InstrumentId) -> anyhow::Result<()> {\n        self.unsubscribe_trade_stream(instrument_id, TradeStreamUse::Ticks)\n            .await\n    }\n\n    /// Unsubscribe from complete public trades for an instrument.\n    pub async fn unsubscribe_public_trades(\n        &self,\n        instrument_id: InstrumentId,\n    ) -> anyhow::Result<()> {\n        self.unsubscribe_trade_stream(instrument_id, TradeStreamUse::PublicTrades)\n            .await\n    }\n\n    async fn unsubscribe_trade_stream(","sourceCodeStart":1846,"sourceCodeEnd":1882,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/hyperliquid/src/websocket/client.rs#L1846-L1882","documentation":"This error wraps a failed send of HandlerCommand::Resubscribe on the internal mpsc command channel, used when re-establishing an existing subscription (e.g. after changing stream options). It fails only when the handler task's receiver is closed, meaning the handler loop is not running. Without the handler, the resubscribe request cannot reach the WebSocket connection.","triggerScenarios":"Calling a resubscribe-capable API (e.g. subscribe_book_depth10_with_options on an active stream with different options, routed through send_resubscribe) after disconnect() or handler-task exit.","commonSituations":"Re-subscribing after a reconnect attempt that left the handler dead; changing depth-10 options on a client whose handler already stopped; shutdown racing a resubscribe.","solutions":["Confirm the handler task is running before resubscribing; reconnect and resubscribe on a fresh client if it exited.","Treat this during teardown as benign and skip the resubscribe.","Serialize resubscribe calls with disconnect/shutdown to avoid races.","Check handler logs for a panic that ended the loop."],"exampleFix":"// before\nclient.disconnect().await?;\nclient.subscribe_book_depth10_with_options(id, Some(2), None).await?; // resubscribe path, channel closed\n\n// after\nclient.connect().await?; // ensure handler is running\nclient.subscribe_book_depth10_with_options(id, Some(2), None).await?;","handlingStrategy":"try-catch","validationCode":"// rust\nif !client.is_connected() {\n    return Err(anyhow::anyhow!(\"cannot resubscribe: client disconnected\"));\n}","typeGuard":null,"tryCatchPattern":"// rust\nif let Err(e) = client.subscribe_book_depth10_with_options(id, Some(2), None).await {\n    if e.to_string().contains(\"resubscribe\") {\n        client = reconnect_client().await?;\n        client.subscribe_book_depth10_with_options(id, Some(2), None).await?;\n    } else { return Err(e); }\n}","preventionTips":["Only resubscribe on a client with a live handler task.","Skip resubscribes during shutdown once a disconnect has begun.","Serialize option-change resubscribes with connection lifecycle changes.","Investigate handler logs when resubscribe sends fail; something ended the loop."],"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-14T05:17:10.506Z"}