{"record":{"id":"09b772200ba35f08","repo":"zed-industries/zed","slug":"timed-out-when-connecting-to-debugger","errorCode":null,"errorMessage":"Timed out when connecting to debugger","messagePattern":"Timed out when connecting to debugger","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/dap/src/transport.rs","lineNumber":345,"sourceCode":"\n    async fn recv_from_server<Stdout>(\n        server_stdout: Stdout,\n        mut message_handler: DapMessageHandler,\n        pending_requests: Arc<Mutex<PendingRequests>>,\n        log_handlers: Option<LogHandlers>,\n    ) -> Result<()>\n    where\n        Stdout: AsyncRead + Unpin + Send + 'static,\n    {\n        let mut recv_buffer = String::new();\n        let mut reader = BufReader::new(server_stdout);\n\n        let result = loop {\n            let result =\n                Self::receive_server_message(&mut reader, &mut recv_buffer, log_handlers.as_ref())\n                    .await;\n            match result {\n                ConnectionResult::Timeout => anyhow::bail!(\"Timed out when connecting to debugger\"),\n                ConnectionResult::ConnectionReset => {\n                    log::info!(\"Debugger closed the connection\");\n                    return Ok(());\n                }\n                ConnectionResult::Result(Ok(Message::Response(res))) => {\n                    let tx = pending_requests.lock().remove(res.request_seq)?;\n                    if let Some(tx) = tx {\n                        if let Err(e) = tx.send(Self::process_response(res)) {\n                            log::trace!(\"Did not send response `{:?}` for a cancelled\", e);\n                        }\n                    } else {\n                        message_handler(Message::Response(res))\n                    }\n                }\n                ConnectionResult::Result(Ok(message)) => message_handler(message),\n                ConnectionResult::Result(Err(e)) => break Err(e),\n            }\n        };","sourceCodeStart":327,"sourceCodeEnd":363,"githubUrl":"https://github.com/zed-industries/zed/blob/f4178619acd0d47ea1f76a2025c42962c6d6638c/crates/dap/src/transport.rs#L327-L363","documentation":"In TransportDelegate's connection loop, receive_server_message returned ConnectionResult::Timeout - no complete DAP message arrived from the adapter's stdout within the receive timeout window - so Zed gives up with 'Timed out when connecting to debugger'. The TCP socket/stdout may be open, but the adapter never spoke DAP when expected.","triggerScenarios":"Starting a debug session where the adapter process launches but never writes its initialize response: adapter hanging on startup (first-run downloads, license prompts), adapter printing non-DAP noise to stdout so framing never matches, extremely slow cold start exceeding the timeout, or the adapter crashing before its first output.","commonSituations":"First launch of a freshly-installed adapter that downloads components; debuggers that prompt interactively (lldb init scripts, license checks); stdout polluted by wrapper scripts (npx, shell echo); overloaded CI machines making startup exceed the fixed window.","solutions":["Run the adapter binary manually with the same arguments and confirm it emits DAP framing on stdout promptly","Remove interactive prompts / heavy init scripts (e.g. .lldbinit, gdb auto-load) from adapter startup","Ensure wrapper scripts do not write anything to stdout - route chatter to stderr","Increase the connection timeout if the adapter legitimately needs longer to start"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// Smoke-test the adapter before wiring it into a session\nlet output = util::command::new_std_command(adapter_path)\n    .arg(\"--version\")\n    .output()\n    .await?;\nanyhow::ensure!(output.status.success(), \"adapter failed smoke test\");","typeGuard":null,"tryCatchPattern":"match start_session(/* .. */).await {\n    Ok(session) => Ok(session),\n    Err(err) if err.to_string().contains(\"Timed out when connecting\") => {\n        // one retry with a longer timeout; then surface adapter stdout logs\n        retry_with_longer_timeout().await\n    }\n    Err(err) => Err(err),\n}","preventionTips":["Keep adapter stdout pristine - all diagnostics go to stderr or log handlers","Disable interactive startup (lldbinit, license prompts) in adapter arguments","Pre-download adapter components so first-launch cold start fits the timeout"],"tags":["dap","timeout","connection","debug-adapter","rust"],"backgroundTag":"debugger-connection-timeout","analyzedSha":"f4178619acd0d47ea1f76a2025c42962c6d6638c","analyzedAt":"2026-08-20T19:29:52.058Z","contentChangedAt":"2026-08-20T19:29:52.058Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}