{"record":{"id":"eb156fe121b4a7df","repo":"nautechsystems/nautilus_trader","slug":"failed-to-send-removebartype-command-e","errorCode":null,"errorMessage":"Failed to send RemoveBarType command: {e}","messagePattern":"Failed to send RemoveBarType command: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/hyperliquid/src/websocket/client.rs","lineNumber":1942,"sourceCode":"\n    /// Unsubscribe from candle/bar data.\n    pub async fn unsubscribe_bars(&self, bar_type: BarType) -> anyhow::Result<()> {\n        let instrument_id = bar_type.instrument_id();\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        let interval = bar_type_to_interval(&bar_type)?;\n        let subscription = SubscriptionRequest::Candle { coin, interval };\n\n        let key = format!(\"candle:{coin}:{interval}\");\n        self.bar_types.remove(&key);\n\n        let cmd_tx = self.cmd_tx.read().await;\n\n        cmd_tx\n            .send(HandlerCommand::RemoveBarType { key })\n            .map_err(|e| anyhow::anyhow!(\"Failed to send RemoveBarType command: {e}\"))?;\n\n        self.send_unsubscription(&cmd_tx, subscription)?;\n        Ok(())\n    }\n\n    /// Unsubscribe from funding rate updates for an instrument.\n    pub async fn unsubscribe_funding_rates(\n        &self,\n        instrument_id: InstrumentId,\n    ) -> anyhow::Result<()> {\n        self.unsubscribe_asset_context_data(instrument_id, AssetContextDataType::FundingRate)\n            .await\n    }\n\n    /// Unsubscribe from open interest updates for an instrument.\n    pub async fn unsubscribe_open_interest(\n        &self,\n        instrument_id: InstrumentId,","sourceCodeStart":1924,"sourceCodeEnd":1960,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/hyperliquid/src/websocket/client.rs#L1924-L1960","documentation":"This error wraps a failed send of RemoveBarType on the internal mpsc command channel while unsubscribing from bars. The client removes the bar key from its local registry and notifies the handler so it can stop routing bar data; failure means the handler task's receiver is closed. The unsubscribe cannot complete because the client is already shut down.","triggerScenarios":"Calling unsubscribe_bars after disconnect(), a handler panic, or drop/cancellation of the handler task; also when runtime shutdown races the unsubscribe call.","commonSituations":"Teardown-order bugs where the handler task is dropped before stream unsubscription; stale client reused after reconnect; shutdown handlers calling unsubscribe after disconnect.","solutions":["During shutdown this is benign — log and continue; the connection is already closed.","Keep the handler task alive until all unsubscriptions complete; fix drop ordering.","If subscriptions must be managed afterwards, re-create/reconnect the client.","Check handler-task logs for the reason the receiver loop ended."],"exampleFix":"// before\nclient.disconnect().await?;\nclient.unsubscribe_bars(bar_type).await?; // channel closed\n\n// after\nclient.unsubscribe_bars(bar_type).await?;\nclient.disconnect().await?;","handlingStrategy":"try-catch","validationCode":"// rust\nif !client.is_connected() {\n    // already torn down; bar routing is gone anyway\n    return Ok(());\n}","typeGuard":null,"tryCatchPattern":"// rust\nif let Err(e) = client.unsubscribe_bars(bar_type).await {\n    if e.to_string().contains(\"RemoveBarType\") && shutting_down {\n        tracing::debug!(\"benign bar unsubscribe after shutdown: {e}\");\n    } else { return Err(e); }\n}","preventionTips":["Unsubscribe bars before disconnect(); never the reverse.","Keep handler task alive until teardown completes (check drop order).","Filter closed-channel errors from metrics during shutdown to avoid noise.","After reconnects, use the fresh client for both subscribe and unsubscribe."],"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"}