{"record":{"id":"c9a272fbfc81a9e8","repo":"Kuberwastaken/claurst","slug":"failed-to-accept-connection","errorCode":null,"errorMessage":"Failed to accept connection: {}","messagePattern":"Failed to accept connection: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src-rust/crates/cli/src/codex_oauth_flow.rs","lineNumber":121,"sourceCode":"\r\n    // Persist tokens and register an account profile in the registry.\r\n    claurst_core::oauth_config::save_codex_tokens_and_register(&tokens, label)?;\r\n\r\n    eprintln!(\"Codex login successful!\");\r\n    Ok(tokens)\r\n}\r\n\r\n/// Wait for OAuth callback on local server, extract code and state.\r\nasync fn wait_for_callback(listener: TcpListener) -> anyhow::Result<(String, String)> {\r\n    use tokio::io::AsyncWriteExt;\r\n\r\n    let (mut socket, _) = tokio::time::timeout(\r\n        std::time::Duration::from_secs(300), // 5 minute timeout\r\n        listener.accept(),\r\n    )\r\n    .await\r\n    .map_err(|_| anyhow!(\"OAuth callback timeout (5 minutes)\"))?\r\n    .map_err(|e| anyhow!(\"Failed to accept connection: {}\", e))?;\r\n\r\n    let mut reader = BufReader::new(&mut socket);\r\n    let mut request_line = String::new();\r\n    reader.read_line(&mut request_line).await?;\r\n\r\n    // Parse \"GET /auth/callback?code=...&state=... HTTP/1.1\"\r\n    let parts: Vec<&str> = request_line.split_whitespace().collect();\r\n    if parts.len() < 2 {\r\n        bail!(\"Invalid HTTP request\");\r\n    }\r\n\r\n    let path = parts[1];\r\n    let query_start = path.find('?').ok_or_else(|| anyhow!(\"No query string in callback\"))?;\r\n    let query = &path[query_start + 1..];\r\n\r\n    let mut code = String::new();\r\n    let mut state = String::new();\r\n    let mut error = String::new();\r","sourceCodeStart":103,"sourceCodeEnd":139,"githubUrl":"https://github.com/Kuberwastaken/claurst/blob/b0637c97ec34144387cbf2f74f65df6d16a6cef1/src-rust/crates/cli/src/codex_oauth_flow.rs#L103-L139","documentation":"The OAuth flow's local HTTP server failed to accept the incoming browser callback connection: `listener.accept()` returned an I/O error, which is wrapped into this message. This is an OS-level accept failure (e.g. socket closed, EMFILE too many open files), distinct from the timeout case.","triggerScenarios":"`listener.accept()` inside `wait_for_callback` returns `Err(io::Error)` — the listener socket was invalidated, the process hit the file-descriptor limit, or the connection was reset at the OS level.","commonSituations":"Process running with `ulimit -n` exhausted (many open files/sockets); container network namespace tearing down the loopback socket; antivirus/security software killing the local connection; system suspend during the wait.","solutions":["Raise the file-descriptor limit (`ulimit -n 4096`) and retry the login.","Check security software or container policies that interfere with loopback connections.","Simply retry the OAuth flow — accept errors are usually transient.","If reproducible, capture the underlying io::Error message for a bug report."],"exampleFix":"// diagnose\n// $ ulimit -n        # if low, raise before running\n// $ ulimit -n 4096 && ./claurst login","handlingStrategy":"retry","validationCode":"// Check fd headroom before starting the flow\n// $ ulimit -n   (raise to >=1024 if low)","typeGuard":null,"tryCatchPattern":"match run_oauth_flow(&mut app).await {\n    Err(e) if e.to_string().contains(\"Failed to accept connection\") => {\n        eprintln!(\"Transient accept failure; retrying login once\");\n        run_oauth_flow(&mut app).await?;\n    }\n    other => other?,\n}","preventionTips":["Raise the file-descriptor limit if you run many concurrent connections.","Retry the login flow — accept failures are usually transient.","Exclude localhost from security software that resets local sockets."],"tags":["oauth","network","socket","cli"],"backgroundTag":"network-request-failed","analyzedSha":"b0637c97ec34144387cbf2f74f65df6d16a6cef1","analyzedAt":"2026-09-10T00:24:58.650Z","contentChangedAt":"2026-09-10T00:24:58.650Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}