MyCATApache/Mycat-Server · error · IllegalArgumentException

Packet size over the limit.

Error message

Packet size over the limit.

What it means

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.

Solutions

  1. Raise maxPacketSize in mycat server/config so it is >= the client's max_allowed_packet and largest expected packet.
  2. Reduce the client-side packet size: set max_allowed_packet and batch size smaller on the application/driver.
  3. Split large writes (e.g. LOAD DATA, bulk INSERT) into smaller batches in the client.
  4. If deliberately huge packets are required, ensure buffer pool can absorb pkgLength before raising the limit to avoid OOM.

Example fix

// before (mycat server.xml)
<property name="maxPacketSize">16M</property>
// after
<property name="maxPacketSize">64M</property>
Defensive patterns

Strategy: validation

Validate before calling

long maxPacket = 16L * 1024 * 1024;
if (payload.length + HEADER_LEN > maxPacket) {
    throw new IllegalArgumentException("payload " + payload.length + " exceeds server maxPacketSize " + maxPacket);
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: payload too large / request exceeds maximum size: why libraries cap bytes and how to fix oversize payloads — this error's family across 50 libraries.

Related errors


AI-assisted analysis of MyCATApache/Mycat-Server@65f8d8beb7 (2026-09-11). Data as JSON: /api/errors/fb14799452f35467. Report an issue: GitHub.

Appendix: source

Thrown at src/main/java/io/mycat/net/AbstractConnection.java:398

				// not read whole message package ,so check if buffer enough and
				// compact readbuffer
				if (!readBuffer.hasRemaining()) {
					readBuffer = ensureFreeSpaceOfReadBuffer(readBuffer, offset, length);
				}
				break;
			}
		}
	}
	
	private boolean isConReadBuffer(ByteBuffer buffer) {
		return buffer.capacity() == processor.getBufferPool().getConReadBuferChunk() && buffer.isDirect();
	}
	
	private ByteBuffer ensureFreeSpaceOfReadBuffer(ByteBuffer buffer,
			int offset, final int pkgLength) {
		// need a large buffer to hold the package
		if (pkgLength > maxPacketSize) {
			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");

View on GitHub (pinned to 65f8d8beb7)