{"record":{"id":"e65f0087d20b6290","repo":"Kuberwastaken/claurst","slug":"failed-to-write-oauth-callback-response","errorCode":null,"errorMessage":"Failed to write OAuth callback response: {}","messagePattern":"Failed to write OAuth callback response: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src-rust/crates/mcp/src/oauth.rs","lineNumber":275,"sourceCode":"        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())\n        .await\n        .map_err(|e| anyhow::anyhow!(\"Failed to write OAuth callback response: {}\", e))?;\n\n    if parsed_url.path() != callback_path {\n        anyhow::bail!(\n            \"OAuth callback path mismatch: expected '{}', got '{}'\",\n            callback_path,\n            parsed_url.path()\n        );\n    }\n\n    if let Some(expected_state) = expected_state {\n        let received_state = parsed_url\n            .query_pairs()\n            .find(|(key, _)| key == \"state\")\n            .map(|(_, value)| value.to_string());\n        if received_state.as_deref() != Some(expected_state) {\n            anyhow::bail!(\"OAuth state mismatch — possible CSRF attack\");\n        }\n    }","sourceCodeStart":257,"sourceCodeEnd":293,"githubUrl":"https://github.com/Kuberwastaken/claurst/blob/b0637c97ec34144387cbf2f74f65df6d16a6cef1/src-rust/crates/mcp/src/oauth.rs#L257-L293","documentation":"Writing the plain-text 'authentication finished' HTTP response back to the browser's callback socket failed. The authorization code was already captured from the request line; this failure means the user-visible success page could not be delivered, e.g. the peer closed the connection early.","triggerScenarios":"Thrown at src-rust/crates/mcp/src/oauth.rs:275 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check for transient network issues on loopback and retry the authentication flow","Inspect the callback socket lifecycle; a browser closing the tab immediately after redirect can abort the write"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"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"}