{"record":{"id":"4d77079a39398202","repo":"nautechsystems/nautilus_trader","slug":"failed-to-connect-spot-public-json-ws-e","errorCode":null,"errorMessage":"Failed to connect Spot public JSON WS: {e}","messagePattern":"Failed to connect Spot public JSON WS: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/binance/src/spot/websocket/public_json/client.rs","lineNumber":551,"sourceCode":"            .zip(self.socket_endpoint.as_ref())\n            .map(|(factory, endpoint)| {\n                let endpoint = if slot_index == 0 {\n                    endpoint.clone()\n                } else {\n                    format!(\"{endpoint}-{slot_index}\")\n                };\n                factory.control(endpoint)\n            });\n        let client = WebSocketClient::builder()\n            .config(config)\n            .message_handler(raw_handler)\n            .ping_handler(ping_handler)\n            .keyed_quotas(keyed_quotas)\n            .default_quota(*BINANCE_WS_CONNECTION_QUOTA)\n            .maybe_state_sink(socket_control.as_ref().map(SocketControl::sink))\n            .connect()\n            .await\n            .map_err(|e| anyhow::anyhow!(\"Failed to connect Spot public JSON WS: {e}\"))?;\n\n        let connection_mode = client.connection_mode_atomic();\n        let reconnect_handle = client.reconnect_handle();\n        let subscriptions_state = SubscriptionState::new('@');\n        let cancellation_token = CancellationToken::new();\n\n        let (cmd_tx, cmd_rx) = tokio::sync::mpsc::unbounded_channel();\n\n        let (bytes_tx, bytes_rx) = tokio::sync::mpsc::unbounded_channel::<Vec<u8>>();\n\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,","sourceCodeStart":533,"sourceCodeEnd":569,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/binance/src/spot/websocket/public_json/client.rs#L533-L569","documentation":"create_connection() builds the WebSocket client (URL, handlers, quotas) and awaits .connect(). This error wraps any failure from that underlying WebSocket connection attempt, e.g. DNS failure, TCP/TLS error, HTTP upgrade rejection, or connection timeout to Binance's Spot WS endpoint.","triggerScenarios":"The underlying ws client's connect() returns Err while opening a new pool slot connection: unreachable host, refused connection, TLS failure, invalid URL, or rejected handshake (proxy/firewall, 4xx/5xx from the endpoint).","commonSituations":"No internet or DNS outage; corporate proxy or firewall blocking wss://stream.binance.com; Binance geo-blocking (e.g. restricted regions); transient Binance outage; wrong stream URL configured.","solutions":["Retry with backoff — most failures are transient network issues; the pool's reconnect machinery may already handle it on later subscribe attempts.","Verify network reachability to the WS host (test wss://stream.binance.com:9443 from the deployment environment).","Check the embedded {e} for the root cause (DNS vs TLS vs HTTP status) and fix accordingly (DNS config, proxy settings, VPN/region).","Confirm the configured URL is the correct Binance Spot WS endpoint and not blocked in your jurisdiction."],"exampleFix":"// before\nclient.connect().await?; // hard fail on transient network blip\n\n// after\nfor attempt in 0..5 {\n    match client.connect().await {\n        Ok(_) => break,\n        Err(e) if attempt < 4 => {\n            log::warn!(\"connect failed ({e}), retrying\");\n            tokio::time::sleep(Duration::from_secs(2u64.pow(attempt))).await;\n        }\n        Err(e) => return Err(e),\n    }\n}","handlingStrategy":"retry","validationCode":"// preflight reachability check\n// tokio::net::TcpStream::connect(\"stream.binance.com:9443\").await?;","typeGuard":null,"tryCatchPattern":"match client.connect().await {\n    Err(e) if e.to_string().contains(\"Failed to connect Spot public JSON WS\") => {\n        log::warn!(\"WS connect failed, retrying with backoff: {e}\");\n        tokio::time::sleep(Duration::from_secs(5)).await;\n        // retry\n    }\n    r => r,\n}","preventionTips":["Implement exponential backoff retries for connection attempts.","Verify the deployment environment can reach wss://stream.binance.com (firewall/proxy/geo checks).","Configure DNS and proxy settings explicitly in containers/CI.","Watch for Binance status page incidents before blaming local config."],"tags":["websocket","network","connection","tls"],"backgroundTag":"connection-refused","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"}