{"record":{"id":"ddabce2bf7c633bb","repo":"nautechsystems/nautilus_trader","slug":"binance-futures-dispatch-task-failed-e","errorCode":null,"errorMessage":"Binance Futures dispatch task failed: {e}","messagePattern":"Binance Futures dispatch task failed: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/binance/src/futures/execution.rs","lineNumber":945,"sourceCode":"    }\n\n    async fn await_dispatch_task(&self) -> anyhow::Result<()> {\n        let _recovery_guard = self.recovery_lock.lock().await;\n        let mut task_slot = self.ws_task.lock().await;\n        let Some(outcome) = finish_task(\n            &mut task_slot,\n            Duration::from_secs(1),\n            Duration::from_secs(2),\n        )\n        .await\n        else {\n            return Ok(());\n        };\n\n        match outcome {\n            TaskJoinOutcome::Completed(()) | TaskJoinOutcome::Aborted => Ok(()),\n            TaskJoinOutcome::Failed(e) => {\n                Err(anyhow::anyhow!(\"Binance Futures dispatch task failed: {e}\"))\n            }\n            TaskJoinOutcome::Incomplete => Err(anyhow::anyhow!(\n                \"Binance Futures dispatch task did not stop after abort\"\n            )),\n        }\n    }\n\n    async fn close_listen_key_slot(\n        &self,\n        slot: &RwLock<Option<SecretString>>,\n        context: &str,\n    ) -> anyhow::Result<()> {\n        let key = slot.read().clone();\n        let Some(key) = key else {\n            return Ok(());\n        };\n\n        self.http_client","sourceCodeStart":927,"sourceCodeEnd":963,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/binance/src/futures/execution.rs#L927-L963","documentation":"await_dispatch_task joins the client's dispatch task (which routes messages from the WebSocket sessions to handlers) and inspects the TaskJoinOutcome; a Failed outcome means the task ended with an error, wrapped in this anyhow message. Called from connect and disconnect, so it can fail both initial connection setup and teardown.","triggerScenarios":"Connecting or disconnecting when the dispatch task panicked or returned an error — e.g. a send handler error, deserialization panic in the message loop, or channel closure while the dispatcher was processing.","commonSituations":"Exchange sending malformed/unexpected frames that break the dispatch loop, a bug in a subscribed data handler, or abrupt channel teardown during disconnect racing in-flight messages.","solutions":["Inspect the error chain for the underlying task error (the {e} in the message)","Reconnect — if connect failed, retry after verifying network and API status","Check subscribed data/instrument handlers for panics or errors that crash the dispatcher","Upgrade to the latest nautilus_trader version for dispatcher robustness fixes"],"exampleFix":"// before\nclient.connect().await?;\n// after\nmatch client.connect().await {\n    Ok(()) => {},\n    Err(e) if e.to_string().contains(\"dispatch task failed\") => {\n        tracing::error!(\"dispatch failure: {e:#}\");\n        tokio::time::sleep(Duration::from_secs(2)).await;\n        client.connect().await?; // retry\n    }\n    Err(e) => return Err(e),\n}","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"if let Err(e) = client.connect().await {\n    if e.to_string().contains(\"dispatch task failed\") {\n        tokio::time::sleep(Duration::from_secs(2)).await;\n        client.connect().await?;\n    } else { return Err(e); }\n}","preventionTips":["Inspect the underlying error chain to find the real task failure","Avoid panicking in data/order handlers","Keep the adapter on a recent version"],"tags":["binance","dispatch","task-panic","websocket"],"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"}