{"record":{"id":"74956354e3a06ebf","repo":"Kuberwastaken/claurst","slug":"failed-to-accept-oauth-callback-connection","errorCode":null,"errorMessage":"Failed to accept OAuth callback connection: {}","messagePattern":"Failed to accept OAuth callback connection: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src-rust/crates/mcp/src/oauth.rs","lineNumber":247,"sourceCode":"        redirect_url.path().to_string()\n    };\n    let listener = TcpListener::bind((host.as_str(), port))\n        .await\n        .map_err(|e| anyhow::anyhow!(\"Failed to bind OAuth callback listener on {}:{}: {}\", host, port, e))?;\n\n    Ok((listener, host, callback_path))\n}\n\nasync fn wait_for_authorization_code(\n    listener: TcpListener,\n    host: &str,\n    callback_path: &str,\n    expected_state: Option<&str>,\n) -> anyhow::Result<String> {\n    let (mut socket, _) = tokio::time::timeout(Duration::from_secs(180), listener.accept())\n        .await\n        .map_err(|_| anyhow::anyhow!(\"Timeout waiting for OAuth callback\"))?\n        .map_err(|e| anyhow::anyhow!(\"Failed to accept OAuth callback connection: {}\", e))?;\n\n    let (reader, mut writer) = socket.split();\n    let mut reader = BufReader::new(reader);\n    let mut request_line = String::new();\n    reader\n        .read_line(&mut request_line)\n        .await\n        .map_err(|e| anyhow::anyhow!(\"Failed to read OAuth callback request: {}\", e))?;\n    loop {\n        let mut header = String::new();\n        reader\n            .read_line(&mut header)\n            .await\n            .map_err(|e| anyhow::anyhow!(\"Failed to read OAuth callback headers: {}\", e))?;\n        if header.trim().is_empty() {\n            break;\n        }\n    }","sourceCodeStart":229,"sourceCodeEnd":265,"githubUrl":"https://github.com/Kuberwastaken/claurst/blob/b0637c97ec34144387cbf2f74f65df6d16a6cef1/src-rust/crates/mcp/src/oauth.rs#L229-L265","documentation":"Raised when listener.accept() itself returns Err (distinct from the timeout case). The TCP listener failed to accept an incoming callback connection, typically because the listener was closed or the OS rejected the accept.","triggerScenarios":"wait_for_authorization_code calling accept() after the listener/socket was closed or the process hit an fd limit (EMFILE/ENFILE); the loopback interface going down mid-flow.","commonSituations":"Too many open files exhausting fds; another thread/task dropped the TcpListener; sandbox/LSM policies interfering with socket operations.","solutions":["Check the inner error ({} placeholder) for the errno (e.g. EMFILE) and address it","Raise the fd limit (ulimit -n) if EMFILE/ENFILE","Ensure no other code closes the listener while the auth session is waiting","Retry the auth flow after fixing the environment"],"exampleFix":"# Raise fd limit\nulimit -n 4096","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"match wait_for_authorization_code(listener, host, path, Some(state)).await {\n    Ok(code) => code,\n    Err(e) if e.to_string().contains(\"accept OAuth callback connection\") => {\n        eprintln!(\"accept failed: {e}; retrying\");\n        retry_flow().await?\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Keep fd limits healthy (ulimit -n)","Never drop the TcpListener while an auth session is pending","Avoid sandboxes that restrict socket ops mid-run"],"tags":["network","tcp","oauth"],"backgroundTag":"connection-refused","analyzedSha":"b0637c97ec34144387cbf2f74f65df6d16a6cef1","analyzedAt":"2026-09-10T00:24:58.650Z","contentChangedAt":"2026-09-10T00:24:58.650Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}