{"record":{"id":"fc341ae95286b391","repo":"MyCATApache/Mycat-Server","slug":"invalid-readbuffer-capacity-too-little-buffer-siz","errorCode":null,"errorMessage":"invalid readbuffer capacity ,too little buffer size ${readBuffer.capacity()}","messagePattern":"invalid readbuffer capacity ,too little buffer size (.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/main/java/io/mycat/net/AbstractConnection.java","lineNumber":326,"sourceCode":"\t\t\tthis.close(\"stream closed\");\n            return;\n\t\t} else if (got == 0\n\t\t\t\t&& !this.channel.isOpen()) {\n\t\t\t\tthis.close(\"socket closed\");\n\t\t\t\treturn;\n\t\t}\n\t\tnetInBytes += got;\n\t\tprocessor.addNetInBytes(got);\n\n\t\t// 循环处理字节信息\n\t\tint offset = readBufferOffset, length = 0, position = readBuffer.position();\n\t\tfor (;;) {\n\t\t\tlength = getPacketLength(readBuffer, offset);\t\t\t\n\t\t\tif (length == -1) {\n\t\t\t\tif (offset != 0) {\n\t\t\t\t\tthis.readBuffer = compactReadBuffer(readBuffer, offset);\n\t\t\t\t} else if (readBuffer != null && !readBuffer.hasRemaining()) {\n\t\t\t\t\tthrow new RuntimeException( \"invalid readbuffer capacity ,too little buffer size \" \n\t\t\t\t\t\t\t+ readBuffer.capacity());\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tif (position >= offset + length && readBuffer != null) {\n\t\t\t\t\n\t\t\t\t// handle this package\n\t\t\t\treadBuffer.position(offset);\t\t\t\t\n\t\t\t\tbyte[] data = new byte[length];\n\t\t\t\treadBuffer.get(data, 0, length);\n\t\t\t\thandle(data);\n\t\t\t\t\n\t\t\t\t// maybe handle stmt_close\n\t\t\t\tif(isClosed()) {\n\t\t\t\t\treturn ;\n\t\t\t\t}\n","sourceCodeStart":308,"sourceCodeEnd":344,"githubUrl":"https://github.com/MyCATApache/Mycat-Server/blob/65f8d8beb752f935752f2a0eec0ab017facab9ef/src/main/java/io/mycat/net/AbstractConnection.java#L308-L344","documentation":"AbstractConnection.onReadData parses packets from the read buffer. When getPacketLength returns -1 (not enough bytes for a header) but the buffer is full (no remaining capacity) and offset is 0, the buffer can never grow to hold even one packet header, so it throws this RuntimeException naming the capacity. It guards against buffers smaller than the minimum MySQL packet header.","triggerScenarios":"readBuffer allocated with capacity smaller than the packet header size (or < packet length) and the buffer fills without a parseable packet; packet length field claims a size larger than buffer capacity with no space left to accumulate; corrupted stream bytes making length unparseable while buffer is full.","commonSituations":"Misconfigured buffer/chunk sizes (e.g. tiny processor buffer size in MyCAT config); client sending oversized or malicious packets; memory pressure reducing buffer pool sizes below protocol minimum.","solutions":["Increase MyCAT's read/processor buffer size configuration so buffers exceed the max expected packet header plus typical packet length.","Check the client for corrupted or non-MySQL protocol traffic (port scanners, wrong protocol).","Verify buffer pool settings after upgrades; ensure bufferChunk respects the MySQL protocol minimum (>= 4 bytes header, realistically KBs).","If reproducible with a specific query/result size, adjust max packet / buffer settings to accommodate it and restart."],"exampleFix":"// before\n<property name=\"processorBufferChunk\">256</property>\n// after\n<property name=\"processorBufferChunk\">4096</property>","handlingStrategy":"validation","validationCode":"// preflight buffer size\nint minHeader = 4; // MySQL packet header\nif (readBufferCapacity < minHeader * 8) {\n    throw new IllegalStateException(\"processorBufferChunk too small: \" + readBufferCapacity);\n}","typeGuard":null,"tryCatchPattern":"try { connection.read(); } catch (RuntimeException e) {\n    if (e.getMessage().startsWith(\"invalid readbuffer capacity\")) {\n        // close connection, raise buffer chunk, reconnect\n    }\n}","preventionTips":["Keep processorBufferChunk comfortably above max_allowed_packet expectations","Reject non-MySQL protocol traffic at the network edge","Re-verify buffer configs after MyCAT upgrades","Set max packet sizes on clients consistent with server buffer settings"],"tags":["network","buffer","protocol","nio"],"backgroundTag":"value-out-of-range","analyzedSha":"65f8d8beb752f935752f2a0eec0ab017facab9ef","analyzedAt":"2026-09-11T00:12:21.696Z","contentChangedAt":"2026-09-11T00:12:21.696Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}