{"record":{"id":"c0a739161dee94e6","repo":"zed-industries/zed","slug":"failed-to-bind-callback-port","errorCode":null,"errorMessage":"failed to bind callback port","messagePattern":"failed to bind callback port","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/client/src/client.rs","lineNumber":1471,"sourceCode":"                        rpc::auth::keypair().context(\"failed to generate keypair for auth\")?;\n                    let public_key = String::try_from(public_key)\n                        .context(\"failed to serialize public key for auth\")?;\n\n                    if let Some((login, token)) =\n                        IMPERSONATE_LOGIN.as_ref().zip(ADMIN_API_TOKEN.as_ref())\n                    {\n                        if !*USE_WEB_LOGIN {\n                            eprintln!(\"authenticate as admin {login}, {token}\");\n\n                            return this\n                                .authenticate_as_admin(http, login.clone(), token.clone())\n                                .await;\n                        }\n                    }\n\n                    // Start an HTTP server to receive the redirect from Zed's sign-in page.\n                    let server = tiny_http::Server::http(\"127.0.0.1:0\")\n                        .map_err(|e| anyhow!(e).context(\"failed to bind callback port\"))?;\n                    let port = server\n                        .server_addr()\n                        .to_ip()\n                        .context(\"server not bound to a TCP address\")?\n                        .port();\n\n                    #[derive(Serialize)]\n                    struct NativeAppSignInQueryParams {\n                        native_app_port: u16,\n                        native_app_public_key: String,\n                        system_id: Option<Arc<str>>,\n                    }\n\n                    // Open the Zed sign-in page in the user's browser, with query parameters that indicate\n                    // that the user is signing in from a Zed app running on the same device.\n                    let url = http.build_url(&format!(\n                        \"/native_app_signin?{}\",\n                        serde_urlencoded::to_string(&NativeAppSignInQueryParams {","sourceCodeStart":1453,"sourceCodeEnd":1489,"githubUrl":"https://github.com/zed-industries/zed/blob/bc538def4545534201bbfcac4e95ac34ea6501b6/crates/client/src/client.rs#L1453-L1489","documentation":"For native app sign-in, Zed starts a tiny HTTP server on 127.0.0.1:0 (ephemeral port) to receive the OAuth redirect. This error means the loopback bind itself failed, so no callback can ever arrive.","triggerScenarios":"tiny_http::Server::http(\"127.0.0.1:0\") returns an error: the OS refuses new sockets — exhausted port range, sandbox denying network listeners, or restrictive container/MAC policies.","commonSituations":"Running Zed inside a sandboxed environment or container without loopback networking; systems with thousands of TIME_WAIT sockets; macOS application-firewall or endpoint-security agents blocking listeners.","solutions":["Run Zed outside sandboxed/containerized environments that block loopback listeners","Check for port exhaustion: close runaway local processes and retry","Temporarily test with the app firewall/security agent disabled to confirm the blocker"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// probe loopback bind capability before starting sign-in\nfn loopback_available() -> bool {\n    std::net::TcpListener::bind(\"127.0.0.1:0\").is_ok()\n}\nif !loopback_available() {\n    anyhow::bail!(\"cannot bind loopback; native sign-in unavailable in this environment\");\n}","typeGuard":null,"tryCatchPattern":"let server = match tiny_http::Server::http(\"127.0.0.1:0\") {\n    Ok(server) => server,\n    Err(err) if err.kind() == std::io::ErrorKind::AddrInUse || err.kind() == std::io::ErrorKind::PermissionDenied => {\n        // transient on busy systems; brief backoff then one retry\n        std::thread::sleep(Duration::from_millis(500));\n        tiny_http::Server::http(\"127.0.0.1:0\").map_err(|e| anyhow!(e).context(\"failed to bind callback port\"))?\n    }\n    Err(err) => return Err(anyhow!(err).context(\"failed to bind callback port\")),\n};","preventionTips":["Avoid running sign-in inside sandboxed containers without loopback","Monitor local socket usage on shared CI machines","Fall back to non-native sign-in flows where listeners are blocked"],"tags":["network","oauth","localhost","sign-in"],"backgroundTag":null,"analyzedSha":"bc538def4545534201bbfcac4e95ac34ea6501b6","analyzedAt":"2026-08-16T07:30:46.435Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}