MyCATApache/Mycat-Server · error · RuntimeException
invalid readbuffer capacity ,too little buffer size
Error message
invalid readbuffer capacity ,too little buffer size ${readBuffer.capacity()} What it means
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.
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.
Example fix
// before <property name="processorBufferChunk">256</property> // after <property name="processorBufferChunk">4096</property>
Defensive patterns
Strategy: validation
Validate before calling
// preflight buffer size
int minHeader = 4; // MySQL packet header
if (readBufferCapacity < minHeader * 8) {
throw new IllegalStateException("processorBufferChunk too small: " + readBufferCapacity);
} Try / catch
try { connection.read(); } catch (RuntimeException e) {
if (e.getMessage().startsWith("invalid readbuffer capacity")) {
// close connection, raise buffer chunk, reconnect
}
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.
Related errors
- not enough space
- unknown status!
- writeNotSend but found connnection close err
- Unknown Packet!
- offer data error!
AI-assisted analysis of MyCATApache/Mycat-Server@65f8d8beb7 (2026-09-11).
Data as JSON: /api/errors/fc341ae95286b391.
Report an issue: GitHub.
Appendix: source
Thrown at src/main/java/io/mycat/net/AbstractConnection.java:326
this.close("stream closed");
return;
} else if (got == 0
&& !this.channel.isOpen()) {
this.close("socket closed");
return;
}
netInBytes += got;
processor.addNetInBytes(got);
// 循环处理字节信息
int offset = readBufferOffset, length = 0, position = readBuffer.position();
for (;;) {
length = getPacketLength(readBuffer, offset);
if (length == -1) {
if (offset != 0) {
this.readBuffer = compactReadBuffer(readBuffer, offset);
} else if (readBuffer != null && !readBuffer.hasRemaining()) {
throw new RuntimeException( "invalid readbuffer capacity ,too little buffer size "
+ readBuffer.capacity());
}
break;
}
if (position >= offset + length && readBuffer != null) {
// handle this package
readBuffer.position(offset);
byte[] data = new byte[length];
readBuffer.get(data, 0, length);
handle(data);
// maybe handle stmt_close
if(isClosed()) {
return ;
}
View on GitHub (pinned to 65f8d8beb7)