{"record":{"id":"ea3b1f8b861c8e57","repo":"nautechsystems/nautilus_trader","slug":"failed-to-start-spot-public-json-ws-bytes-task-e","errorCode":null,"errorMessage":"Failed to start Spot public JSON WS bytes task: {e}","messagePattern":"Failed to start Spot public JSON WS bytes task: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/binance/src/spot/websocket/public_json/client.rs","lineNumber":579,"sourceCode":"\n        let mut bytes_task = TaskSlot::new();\n        if let Err(e) = bytes_task.spawn(async move {\n            let mut raw_rx = raw_rx;\n            while let Some(msg) = raw_rx.recv().await {\n                let data = match msg {\n                    Message::Binary(data) => data.to_vec(),\n                    Message::Text(text) => text.as_bytes().to_vec(),\n                    Message::Close(_) => break,\n                    Message::Ping(_) | Message::Pong(_) | Message::Frame(_) => continue,\n                };\n\n                if bytes_tx.send(data).is_err() {\n                    break;\n                }\n            }\n        }) {\n            let shutdown_error = finish_slot_task(&mut bytes_task, \"Binance Spot WS bytes\").await;\n            anyhow::bail!(match shutdown_error {\n                Some(shutdown_error) => format!(\n                    \"Failed to start Spot public JSON WS bytes task: {e}; startup rollback failed: \\\n                     {shutdown_error}\"\n                ),\n                None => format!(\"Failed to start Spot public JSON WS bytes task: {e}\"),\n            });\n        }\n\n        let mut handler = BinanceSpotPublicWsHandler::new(\n            self.signal.clone(),\n            cmd_rx,\n            bytes_rx,\n            subscriptions_state.clone(),\n            self.request_id_counter.clone(),\n        );\n\n        cmd_tx\n            .send(BinanceSpotPublicWsCommand::SetClient(client))","sourceCodeStart":561,"sourceCodeEnd":597,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/binance/src/spot/websocket/public_json/client.rs#L561-L597","documentation":"In create_connection, spawning the bytes-reading task for a public JSON WS slot failed (the spawn/send error `e`); the code rolls back by finishing the already-created handler task and bails. If the rollback itself also errors, the message appends 'startup rollback failed' with that shutdown error. Either way the slot connection was not established.","triggerScenarios":"create_connection (called by connect and subscribe adding a new slot) failing when the bytes task cannot be spawned or immediately errors — e.g. tokio runtime shutdown, spawn failure, or the WS read stream erroring at start.","commonSituations":"Starting connections inside a runtime that is shutting down; resource exhaustion (task limits); a WebSocket already broken by network failure so the bytes task dies instantly at startup.","solutions":["Retry connect/subscribe — if the failure was transient (network/runtime hiccup), a fresh create_connection usually succeeds.","Verify the tokio runtime is alive and not shutting down when creating connections.","Check the rollback suffix in the message: if 'startup rollback failed' appears, there are leaked task resources to investigate.","Check network reachability to Binance and proxy/firewall settings before retrying."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"for attempt in 0..3 {\n    match client.connect().await {\n        Ok(()) => break,\n        Err(e) if e.to_string().contains(\"bytes task\") && attempt < 2 => tokio::time::sleep(backoff(attempt)).await,\n        Err(e) => return Err(e),\n    }\n}","preventionTips":["Create WS connections only on a healthy, non-shutting-down tokio runtime.","Verify network/proxy reachability to Binance before initializing streams.","Watch for 'startup rollback failed' in the message — it signals resource leaks needing deeper investigation.","Use bounded retry with backoff around connection startup."],"tags":["websocket","binance","spot","task-spawn","startup"],"backgroundTag":"network-request-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"}