{"record":{"id":"fb14799452f35467","repo":"MyCATApache/Mycat-Server","slug":"packet-size-over-the-limit","errorCode":null,"errorMessage":"Packet size over the limit.","messagePattern":"Packet size over the limit\\.","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/io/mycat/net/AbstractConnection.java","lineNumber":398,"sourceCode":"\t\t\t\t// not read whole message package ,so check if buffer enough and\n\t\t\t\t// compact readbuffer\n\t\t\t\tif (!readBuffer.hasRemaining()) {\n\t\t\t\t\treadBuffer = ensureFreeSpaceOfReadBuffer(readBuffer, offset, length);\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\t\n\tprivate boolean isConReadBuffer(ByteBuffer buffer) {\n\t\treturn buffer.capacity() == processor.getBufferPool().getConReadBuferChunk() && buffer.isDirect();\n\t}\n\t\n\tprivate ByteBuffer ensureFreeSpaceOfReadBuffer(ByteBuffer buffer,\n\t\t\tint offset, final int pkgLength) {\n\t\t// need a large buffer to hold the package\n\t\tif (pkgLength > maxPacketSize) {\n\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\");","sourceCodeStart":380,"sourceCodeEnd":416,"githubUrl":"https://github.com/MyCATApache/Mycat-Server/blob/65f8d8beb752f935752f2a0eec0ab017facab9ef/src/main/java/io/mycat/net/AbstractConnection.java#L380-L416","documentation":"AbstractConnection.ensureFreeSpaceOfReadBuffer throws IllegalArgumentException when a MySQL protocol packet's decoded length (pkgLength) exceeds maxPacketSize. The server refuses to allocate/read packets larger than the configured limit, since buffering them would risk OOM. It is a deliberate protocol-level guard, not a bug.","triggerScenarios":"onReadData parses a packet header whose 3-byte length field exceeds maxPacketSize while reading from a front-end or back-end connection's socket channel.","commonSituations":"Client sends multi-MB INSERT/UPDATE blobs or LOAD DATA payloads while mycat's maxPacketSize (default ~16MB) is smaller than the client's max_allowed_packet; replication/import tools pushing huge batches through proxy.","solutions":["Raise maxPacketSize in mycat server/config so it is >= the client's max_allowed_packet and largest expected packet.","Reduce the client-side packet size: set max_allowed_packet and batch size smaller on the application/driver.","Split large writes (e.g. LOAD DATA, bulk INSERT) into smaller batches in the client.","If deliberately huge packets are required, ensure buffer pool can absorb pkgLength before raising the limit to avoid OOM."],"exampleFix":"// before (mycat server.xml)\n<property name=\"maxPacketSize\">16M</property>\n// after\n<property name=\"maxPacketSize\">64M</property>","handlingStrategy":"validation","validationCode":"long maxPacket = 16L * 1024 * 1024;\nif (payload.length + HEADER_LEN > maxPacket) {\n    throw new IllegalArgumentException(\"payload \" + payload.length + \" exceeds server maxPacketSize \" + maxPacket);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep client max_allowed_packet <= mycat maxPacketSize","Chunk large bulk inserts / LOAD DATA into smaller batches","Document packet size limits for services writing through mycat"],"tags":["mysql-protocol","packet-size","network","configuration"],"backgroundTag":"payload-too-large","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"}