{"record":{"id":"89fb6edcbafa3b9a","repo":"Kuberwastaken/claurst","slug":"failed-to-read-oauth-callback-request","errorCode":null,"errorMessage":"Failed to read OAuth callback request: {}","messagePattern":"Failed to read OAuth callback request: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"warning","filePath":"src-rust/crates/mcp/src/oauth.rs","lineNumber":255,"sourceCode":"\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    }\n\n    let path = request_line.split_whitespace().nth(1).unwrap_or(\"\");\n    let parsed_url = url::Url::parse(&format!(\"http://{}{}\", host, path))\n        .map_err(|e| anyhow::anyhow!(\"Failed to parse OAuth callback URL '{}': {}\", path, e))?;\n\n    let response = \"HTTP/1.1 200 OK\\r\\nContent-Type: text/plain; charset=utf-8\\r\\nConnection: close\\r\\n\\r\\nMCP OAuth authentication finished. You can close this tab.\\r\\n\";\n    writer\n        .write_all(response.as_bytes())","sourceCodeStart":237,"sourceCodeEnd":273,"githubUrl":"https://github.com/Kuberwastaken/claurst/blob/b0637c97ec34144387cbf2f74f65df6d16a6cef1/src-rust/crates/mcp/src/oauth.rs#L237-L273","documentation":"After accepting the browser's callback connection, reading the HTTP request line from the socket failed at the I/O level (connection reset, timeout, or broken socket before a full line arrived). The browser connected but the request could not be read.","triggerScenarios":"wait_for_authorization_code reading the request line when the client disconnects abruptly, a port scanner or health probe opens and immediately closes the connection, or TLS is attempted against the plain-HTTP listener.","commonSituations":"Antivirus/security software probing the open port; browser preconnect connections torn down; an https:// redirect URI registered with the provider while the listener is plain http.","solutions":["Retry the auth flow — a single aborted probe connection shouldn't prevent the real browser request","Register an http:// (not https://) redirect URI with the OAuth provider so the browser speaks plain HTTP","Exclude the callback port from port-scanning security agents","Check proxies/middleware that might reset loopback connections"],"exampleFix":"// before\n\"redirect_uris\": [\"https://127.0.0.1:8090/callback\"]\n// after\n\"redirect_uris\": [\"http://127.0.0.1:8090/callback\"]","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"match run_mcp_auth_flow(server).await {\n    Err(e) if e.to_string().contains(\"read OAuth callback request\") => {\n        eprintln!(\"callback read interrupted; retrying\");\n        run_mcp_auth_flow(server).await\n    }\n    other => other,\n}","preventionTips":["Register http:// (not https://) redirect URIs with the provider for local callbacks","Bind only to 127.0.0.1 to minimize stray connections","Exclude the callback port from port-scanning security tools"],"tags":["network","http","oauth"],"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-17T15:17:12.973Z"}