MyCATApache/Mycat-Server · error · RuntimeException
not enough space
Error message
not enough space
What it means
ensureFreeSpaceOfReadBuffer throws RuntimeException(" not enough space") when the current packet does not exceed maxPacketSize but the read buffer cannot fit it: the buffer is already at position 0 (no compaction possible) and its capacity is smaller than pkgLength, so there is no way to make room. This signals a buffer-sizing/fragmentation edge case in the NIO read path.
Solutions
- Increase the processor bufferPool buffer sizes (bufferChunk/`bufferNodeSize`) so a single buffer can hold typical packet lengths.
- Increase maxPacketSize check alignment: ensure buffer allocation uses pkgLength (the code allocates pkgLength — verify the version; upgrade mycat where this path allocates a pkgLength-sized buffer).
- Reduce packet sizes on the client (smaller batches, max_allowed_packet).
- If reproducible, capture packet length and upgrade to a mycat release fixing large-packet read-buffer handling.
Defensive patterns
Strategy: validation
Validate before calling
if (packetLength > expectedReadBufferCapacity) {
LOGGER.warn("packet {} larger than read buffer {}", packetLength, expectedReadBufferCapacity);
} Prevention
- Size processor bufferPool buffers larger than the max frequent packet
- Keep maxPacketSize consistent with buffer pool sizing
- Load-test with production-sized rows before deploying
When it happens
Trigger: onReadData -> ensureFreeSpaceOfReadBuffer with buffer.capacity() < pkgLength, offset == 0 (cannot compact), and the buffer pool returns a buffer too small or allocation path bypassed; typically a large packet arriving into a small read buffer.
Common situations: Buffer pool configured with bufferChunk/page sizes smaller than the packets being read (large rows/images), often combined with a mismatched processor bufferPool configuration after upgrading or tuning mycat.
Understand the failure class
Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.
Related errors
- invalid readbuffer capacity ,too little buffer size
- Packet size over the limit.
- writeNotSend but found connnection close err
- offer data error!
- unknown status!
AI-assisted analysis of MyCATApache/Mycat-Server@65f8d8beb7 (2026-09-11).
Data as JSON: /api/errors/7915c6eb6cd8b954.
Report an issue: GitHub.
Appendix: source
Thrown at src/main/java/io/mycat/net/AbstractConnection.java:416
throw new IllegalArgumentException("Packet size over the limit.");
} else if (buffer.capacity() < pkgLength) {
ByteBuffer newBuffer = processor.getBufferPool().allocate(pkgLength);
lastLargeMessageTime = TimeUtil.currentTimeMillis();
buffer.position(offset);
newBuffer.put(buffer);
readBuffer = newBuffer;
recycle(buffer);
readBufferOffset = 0;
return newBuffer;
} else {
if (offset != 0) {
// compact bytebuffer only
return compactReadBuffer(buffer, offset);
} else {
throw new RuntimeException(" not enough space");
}
}
}
private ByteBuffer compactReadBuffer(ByteBuffer buffer, int offset) {
if(buffer == null) {
return null;
}
buffer.limit(buffer.position());
buffer.position(offset);
buffer = buffer.compact();
readBufferOffset = 0;
return buffer;
}
public void write(byte[] data) {
ByteBuffer buffer = allocate();
buffer = writeToBuffer(data, buffer);View on GitHub (pinned to 65f8d8beb7)