{"record":{"id":"825c55a8a0103d9a","repo":"nautechsystems/nautilus_trader","slug":"failed-to-connect-to-tardis-machine-e","errorCode":null,"errorMessage":"Failed to connect to Tardis Machine: {e}","messagePattern":"Failed to connect to Tardis Machine: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/tardis/src/data.rs","lineNumber":578,"sourceCode":"            .bootstrap_instruments(&exchanges)\n            .await\n            .map_err(|e| anyhow::anyhow!(\"Failed to bootstrap instruments: {e}\"))?;\n\n        for instrument in instruments {\n            if let Err(e) = self.data_sender.send(DataEvent::Instrument(instrument)) {\n                log::error!(\"Failed to send instrument event: {e}\");\n            }\n        }\n\n        let url = self.build_ws_url(&base_url)?;\n\n        let mode_label = if is_stream_mode { \"stream\" } else { \"replay\" };\n        log::info!(\"Connecting to Tardis Machine {mode_label}\");\n        log::debug!(\"URL: {url}\");\n\n        let (ws_stream, _) = connect_async(&url)\n            .await\n            .map_err(|e| anyhow::anyhow!(\"Failed to connect to Tardis Machine: {e}\"))?;\n\n        log::info!(\"Connected to Tardis Machine\");\n\n        if let Err(e) = self.spawn_ws_task(\n            ws_stream,\n            url,\n            instrument_map,\n            book_snapshot_output,\n            extract_bbo_as_quotes,\n            is_stream_mode,\n        ) {\n            self.tasks.begin_shutdown();\n            if let Err(teardown_error) = self\n                .tasks\n                .finish_shutdown(Duration::from_secs(1), Duration::from_secs(2))\n                .await\n            {\n                return Err(e.context(format!(\"Tardis startup teardown failed: {teardown_error}\")));","sourceCodeStart":560,"sourceCodeEnd":596,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/tardis/src/data.rs#L560-L596","documentation":"Raised in connect when the initial WebSocket handshake to the Tardis Machine fails (connect_async returns Err). The client cannot establish the WS connection to the local/remote Tardis Machine endpoint.","triggerScenarios":"connect_async(&url) fails: Tardis Machine not running, wrong host/port in config, TLS failure, connection refused/timeout, or invalid URL scheme.","commonSituations":"Tardis Machine Docker container not started or not listening on the configured port; wrong machine URL (http vs ws scheme); firewall/proxy blocking the connection.","solutions":["Confirm Tardis Machine is running and reachable (docker ps / curl its health endpoint).","Check the configured URL: correct host, port, and ws:// (or wss://) scheme.","Verify no firewall or proxy blocks the WebSocket connection.","Check `{e}`: 'Connection refused' means wrong port/host or service down."],"exampleFix":"// before\nurl: \"http://localhost:8000\".into(),\n// after: WebSocket endpoint, not http\nurl: \"ws://localhost:8000\".into(),","handlingStrategy":"validation","validationCode":"// Reachability + scheme pre-check before connecting\nlet url = config.machine_url.clone();\nanyhow::ensure!(url.starts_with(\"ws://\") || url.starts_with(\"wss://\"), \"machine URL must be ws(s)://, got {url}\");\nlet host = url.trim_start_matches(\"ws://\").trim_start_matches(\"wss://\");\ntokio::net::TcpStream::connect(host).await?; // fails fast if Tardis Machine is down","typeGuard":null,"tryCatchPattern":"match client.connect().await {\n    Err(e) if e.to_string().contains(\"Failed to connect to Tardis Machine\") => {\n        log::error!(\"is Tardis Machine running at the configured URL? {e}\");\n        // restart the machine container, then retry\n    }\n    other => other?,\n}","preventionTips":["Add a health check that Tardis Machine is up before starting the client.","Use the correct ws:// or wss:// scheme and port in the machine URL.","Confirm container port mappings (docker ps) match the config."],"tags":["websocket","network","connection"],"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"}