{"record":{"id":"5cb94e6fb6d72e60","repo":"nautechsystems/nautilus_trader","slug":"failed-to-start-user-stream-dispatch-task-e","errorCode":null,"errorMessage":"failed to start user stream dispatch task: {e}","messagePattern":"failed to start user stream dispatch task: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/binance/src/futures/execution.rs","lineNumber":1845,"sourceCode":"            proxy_url: self.config.proxy_url.clone(),\n            socket_factory: self.socket_factory.clone(),\n        };\n\n        let ws_client =\n            build_and_connect_user_stream(&ws_build_params, listen_key.expose_secret()).await?;\n        let stream = ws_client.stream();\n        *self.ws_client.lock() = Some(ws_client);\n\n        self.ws_task\n            .lock()\n            .await\n            .spawn(run_user_stream_dispatch(\n                stream,\n                dispatch_ctx.clone(),\n                recovery_tx.clone(),\n                dispatch_user_stream_message,\n            ))\n            .map_err(|e| anyhow::anyhow!(\"failed to start user stream dispatch task: {e}\"))?;\n\n        // Start listen key keepalive task\n        {\n            let http_client = self.http_client.clone();\n            let listen_key_ref = self.listen_key.clone();\n            let cancel = self.cancellation_token.clone();\n            let recovery_tx = recovery_tx.clone();\n\n            self.session_tasks.spawn(async move {\n                let mut interval =\n                    tokio::time::interval(Duration::from_secs(LISTEN_KEY_KEEPALIVE_SECS));\n                let mut consecutive_failures: u32 = 0;\n\n                loop {\n                    tokio::select! {\n                        _ = interval.tick() => {\n                            let key = {\n                                let guard = listen_key_ref.read();","sourceCodeStart":1827,"sourceCodeEnd":1863,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/binance/src/futures/execution.rs#L1827-L1863","documentation":"Raised in BinanceFuturesExecutionClient::connect when spawning the tokio task that dispatches Binance user-data-stream messages (run_user_stream_dispatch) fails. The spawn itself returned an error (e.g. JoinHandle error from the runtime), so the client cannot consume account/order updates from the private WebSocket stream and connect aborts rather than running silently without user-stream data.","triggerScenarios":"self.ws_task spawn of run_user_stream_dispatch returns Err — typically when the tokio runtime is shutting down, the spawning task handle's runtime has been dropped, or resource exhaustion prevents new task creation during connect().","commonSituations":"Stopping a live node while connect() is mid-flight, running the node with a runtime that is being torn down, or calling connect from outside a live async runtime context.","solutions":["Ensure the tokio runtime is running and not shutting down when connect() is called; await connect fully before beginning shutdown.","Retry connect after a clean disconnect once the runtime is healthy.","Check the inner `{e}` message for the concrete spawn failure (e.g. shutdown vs panic) and address that cause.","If using a custom runtime setup, verify ws_task's handle belongs to the same live runtime as the client."],"exampleFix":"// before\n// begin_shutdown called concurrently with connect\ntokio::join!(async { client.connect().await }, shutdown());\n\n// after\nclient.connect().await?;\n// then trigger shutdown\nshutdown().await;","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"match client.connect().await {\n    Err(e) if e.to_string().contains(\"dispatch task\") => {\n        // runtime likely shutting down; retry on a live runtime\n        tokio::time::sleep(Duration::from_secs(1)).await;\n        client.connect().await?;\n    }\n    r => r?,\n}","preventionTips":["Only call connect() from a live, healthy tokio runtime","Never begin node shutdown concurrently with connect()","Read the inner spawn error to distinguish shutdown from panic"],"tags":["binance","tokio","websocket","task-spawn","user-stream"],"backgroundTag":"task-spawn-failed","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"}