apache/cassandra · error · org.apache.cassandra.transport.ProtocolException

Not enough bytes to read an UTF8 serialized string preceded…

Error message

Not enough bytes to read an UTF8 serialized string preceded by its 4 bytes length

What it means

CBUtil.readLongString(ByteBuf) reads a 4-byte int length then that many UTF-8 bytes. When fewer bytes remain than the declared length (IndexOutOfBoundsException), it throws ProtocolException describing the long-string framing. Same family as the short-string guard but for 4-byte-length fields like query strings.

Solutions

  1. Check intermediaries (proxies, LBs, MTU/SSL offload) for truncation of large frames
  2. Ensure the client native protocol version matches the server's expectations
  3. Reconnect to resync and reproduce with driver debug logging
  4. Validate the declared 4-byte length against frame size when crafting custom clients
Defensive patterns

Strategy: try-catch

Try / catch

try { ... } catch (ProtocolException e) { if (e.getMessage().contains("preceded by its 4 bytes length")) { reconnectSession(); } else throw e; }

Prevention

When it happens

Trigger: A long string field (e.g., CQL query string) declares a length larger than the remaining readable bytes — truncated frame, bogus length prefix, or desynced parsing.

Common situations: Very large queries cut off by intermediaries; corrupt frame from a buggy driver; protocol version mismatch during handshake.

Related errors


AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10). Data as JSON: /api/errors/557a54b8949bcc7e. Report an issue: GitHub.

Appendix: source

Thrown at src/java/org/apache/cassandra/transport/CBUtil.java:214

     * Returns the ecoding size of a US-ASCII string. It does not work if containing any char > 0x007F (127)
     * @param str satisfies {@link org.apache.cassandra.db.marshal.AsciiType}
     *             i.e. seven-bit ASCII, a.k.a. ISO646-US
     */
    public static int sizeOfAsciiString(String str)
    {
        return 2 + str.length();
    }

    public static String readLongString(ByteBuf cb)
    {
        try
        {
            int length = cb.readInt();
            return readString(cb, length);
        }
        catch (IndexOutOfBoundsException e)
        {
            throw new ProtocolException("Not enough bytes to read an UTF8 serialized string preceded by its 4 bytes length");
        }
    }

    public static void writeLongString(String str, ByteBuf cb)
    {
        int length = encodedUTF8Length(str);
        cb.writeInt(length);
        ByteBufUtil.reserveAndWriteUtf8(cb, str, length);
    }

    public static int sizeOfLongString(String str)
    {
        return 4 + encodedUTF8Length(str);
    }

    public static byte[] readBytes(ByteBuf cb)
    {
        try

View on GitHub (pinned to 88fd0f6a0e)