{"record":{"id":"7915c6eb6cd8b954","repo":"MyCATApache/Mycat-Server","slug":"not-enough-space","errorCode":null,"errorMessage":" not enough space","messagePattern":" not enough space","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/main/java/io/mycat/net/AbstractConnection.java","lineNumber":416,"sourceCode":"\t\t\tthrow new IllegalArgumentException(\"Packet size over the limit.\");\n\t\t} else if (buffer.capacity() < pkgLength) {\n\t\t\n\t\t\tByteBuffer newBuffer = processor.getBufferPool().allocate(pkgLength);\n\t\t\tlastLargeMessageTime = TimeUtil.currentTimeMillis();\n\t\t\tbuffer.position(offset);\n\t\t\tnewBuffer.put(buffer);\n\t\t\treadBuffer = newBuffer;\n\n\t\t\trecycle(buffer);\n\t\t\treadBufferOffset = 0;\n\t\t\treturn newBuffer;\n\n\t\t} else {\n\t\t\tif (offset != 0) {\n\t\t\t\t// compact bytebuffer only\n\t\t\t\treturn compactReadBuffer(buffer, offset);\n\t\t\t} else {\n\t\t\t\tthrow new RuntimeException(\" not enough space\");\n\t\t\t}\n\t\t}\n\t}\n\t\n\tprivate ByteBuffer compactReadBuffer(ByteBuffer buffer, int offset) {\n\t\tif(buffer == null) {\n\t\t\treturn null;\n\t\t}\n\t\tbuffer.limit(buffer.position());\n\t\tbuffer.position(offset);\n\t\tbuffer = buffer.compact();\n\t\treadBufferOffset = 0;\n\t\treturn buffer;\n\t}\n\n\tpublic void write(byte[] data) {\n\t\tByteBuffer buffer = allocate();\n\t\tbuffer = writeToBuffer(data, buffer);","sourceCodeStart":398,"sourceCodeEnd":434,"githubUrl":"https://github.com/MyCATApache/Mycat-Server/blob/65f8d8beb752f935752f2a0eec0ab017facab9ef/src/main/java/io/mycat/net/AbstractConnection.java#L398-L434","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"if (packetLength > expectedReadBufferCapacity) {\n    LOGGER.warn(\"packet {} larger than read buffer {}\", packetLength, expectedReadBufferCapacity);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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"],"tags":["nio","buffer","packet-size","network"],"backgroundTag":"internal-invariant-violation","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"}