{"record":{"id":"bb66f5a52599885e","repo":"Kuberwastaken/claurst","slug":"failed-reading-sse-stream","errorCode":null,"errorMessage":"failed reading SSE stream: {}","messagePattern":"failed reading SSE stream: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src-rust/crates/mcp/src/lib.rs","lineNumber":509,"sourceCode":"            \"data\" => data_lines.push(value.to_string()),\r\n            _ => {}\r\n        }\r\n    }\r\n\r\n    pub(crate) async fn process_sse_response<F>(\r\n        response: reqwest::Response,\r\n        mut on_event: F,\r\n    ) -> anyhow::Result<()>\r\n    where\r\n        F: FnMut(Option<&str>, &str) -> anyhow::Result<()>,\r\n    {\r\n        let mut stream = response.bytes_stream();\r\n        let mut buffer = String::new();\r\n        let mut event_name: Option<String> = None;\r\n        let mut data_lines: Vec<String> = Vec::new();\r\n\r\n        while let Some(chunk) = stream.next().await {\r\n            let chunk = chunk.map_err(|e| anyhow::anyhow!(\"failed reading SSE stream: {}\", e))?;\r\n            buffer.push_str(&String::from_utf8_lossy(&chunk));\r\n\r\n            while let Some(pos) = buffer.find('\\n') {\r\n                let mut line: String = buffer.drain(..=pos).collect();\r\n                if line.ends_with('\\n') {\r\n                    line.pop();\r\n                }\r\n                if line.ends_with('\\r') {\r\n                    line.pop();\r\n                }\r\n                if line.is_empty() {\r\n                    dispatch_sse_event(&mut event_name, &mut data_lines, &mut on_event)?;\r\n                } else {\r\n                    process_sse_line(&line, &mut event_name, &mut data_lines);\r\n                }\r\n            }\r\n        }\r\n\r","sourceCodeStart":491,"sourceCodeEnd":527,"githubUrl":"https://github.com/Kuberwastaken/claurst/blob/b0637c97ec34144387cbf2f74f65df6d16a6cef1/src-rust/crates/mcp/src/lib.rs#L491-L527","documentation":"While consuming a server-sent-events stream from an MCP server, the reqwest bytes_stream yielded an Err. The library wraps the underlying transport error (hyper/reqwest/io) in this message, so the displayed cause is the raw stream read failure.","triggerScenarios":"Calling an MCP server over SSE and the TCP connection breaks mid-stream: server crash, network drop, proxy idle timeout, TLS termination, or reqwest body read error.","commonSituations":"Long-lived SSE connections killed by load balancer idle timeouts; server restarted during a request; flaky network or VPN disconnect; TLS certificate issues surfacing mid-stream.","solutions":["Retry the request; add reconnect/backoff logic for long SSE streams","Check server and reverse-proxy idle timeouts and raise them","Verify network/TLS stability between client and MCP server","Inspect the wrapped cause (`{}` payload) for the concrete hyper/io error"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"match read_sse().await {\n    Err(e) if e.to_string().contains(\"failed reading SSE stream\") => {\n        backoff_retry(|| read_sse(), 3).await?\n    }\n    r => r?,\n}","preventionTips":["Raise LB/proxy idle timeouts for SSE connections","Implement automatic reconnect with exponential backoff","Monitor network/TLS health between client and MCP servers"],"tags":["network","sse","streaming","io"],"backgroundTag":"http-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"}