{"record":{"id":"04bd2377768c0029","repo":"valeriansaliou/sonic","slug":"buffer-overflow-bytes","errorCode":null,"errorMessage":"buffer overflow ({}/{} bytes)","messagePattern":"buffer overflow \\((.+?)/(.+?) bytes\\)","errorType":"panic","errorClass":"panic","httpStatus":null,"severity":"error","filePath":"server/src/channel/handle.rs","lineNumber":209,"sourceCode":"                    }\n\n                    // Check for buffer overflow.\n                    // NOTE: To avoid a needless read of `MAX_LINE_SIZE` bytes,\n                    //   we also ensure there is enough space for the line\n                    //   separator. If there isn’t, next loop cycle will abort\n                    //   because the line is too long anyway.\n                    let separator_len = char::from(BUFFER_LINE_SEPARATOR).len_utf8();\n\n                    if (buffer.len() + read.len()) < (MAX_LINE_SIZE - separator_len) {\n                        buffer.extend(read);\n                    } else {\n                        // Do not continue, as there is too much pending data\n                        // in the buffer. Most likely the client does not\n                        // implement a proper back-pressure management system,\n                        // thus we terminate it.\n                        tracing::error!(\"closing channel thread because of buffer overflow\");\n\n                        panic!(\n                            \"buffer overflow ({}/{} bytes)\",\n                            buffer.len() + read.len(),\n                            MAX_LINE_SIZE\n                        );\n                    }\n                }\n                Err(err) => {\n                    tracing::error!(\"closing channel thread with traceback: {}\", err);\n\n                    panic!(\"closing channel\");\n                }\n            }\n        }\n    }\n\n    fn ensure_start(&self, mut stream: &TcpStream) -> Result<ChannelMode, ChannelHandleError> {\n        #[allow(clippy::never_loop)]\n        loop {","sourceCodeStart":191,"sourceCodeEnd":227,"githubUrl":"https://github.com/valeriansaliou/sonic/blob/e6a72da6a532bc3f31d7d93ef1e0964a1a5d01b2/server/src/channel/handle.rs#L191-L227","documentation":"The server's channel thread panics when a single incoming line would exceed MAX_LINE_SIZE (BUFFER_SIZE + LINE_END_GAP + 1). Sonic treats this as a client that does not implement back-pressure, so it terminates the connection thread to protect the buffer.","triggerScenarios":"A client sends one command/line whose size (buffer.len() + read.len()) exceeds MAX_LINE_SIZE over the TCP channel in handle_stream, e.g. a QUERY/PUSH payload larger than the server buffer without a newline terminator.","commonSituations":"Bulk-loading very large strings via PUSH; naive clients writing megabytes without chunking; misconfigured proxies concatenating frames; load-testing tools sending oversized lines.","solutions":["Split large data into commands smaller than the server's MAX_LINE_SIZE (~ BUFFER_SIZE + LINE_END_GAP + 1 bytes)","Chunk large PUSH payloads into multiple commands","Reduce payload size (truncate/index only the needed text)","If you control the deployment, raise the buffer size in the server config to fit your largest command"],"exampleFix":"// client\n// before\nconn.send(format!(\"PUSH collection bucket {}\", huge_text)); // > MAX_LINE_SIZE\n// after\nfor chunk in chunk_text(huge_text, MAX_LINE_SIZE) {\n    conn.send(format!(\"PUSH collection bucket {}\", chunk));\n}","handlingStrategy":"validation","validationCode":"const MAX_LINE_SIZE: usize = /* server BUFFER_SIZE + LINE_END_GAP + 1 */;\nif payload.len() > MAX_LINE_SIZE {\n    // split into chunked commands before sending\n}","typeGuard":null,"tryCatchPattern":"// server-side is a panic; clients should just keep under the limit\n// catch the connection close if you drive the socket yourself\nmatch stream.write_all(line.as_bytes()) {\n    Ok(_) => {},\n    Err(e) => reconnect(),\n}","preventionTips":["Chunk large PUSH/QUERY payloads below MAX_LINE_SIZE","Implement back-pressure in custom clients","Track Sonic's BUFFER_SIZE when upgrading and re-check limits"],"tags":["network","panic","buffer","protocol"],"backgroundTag":"buffer-overflow","analyzedSha":"e6a72da6a532bc3f31d7d93ef1e0964a1a5d01b2","analyzedAt":"2026-09-01T14:10:00.384Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T20:17:18.057Z"}