aeron-io/aeron · error · IllegalStateException

length overflow:

Error message

length overflow: 

What it means

validateAndComputeLength() sums the lengths of all vectors and throws IllegalStateException when the running total becomes negative, which can only happen through int overflow — the combined vector data exceeds Integer.MAX_VALUE (2GB). Aeron throws this because a message length cannot be represented as a positive int for the vectored write protocol.

Solutions

  1. Cap total batch size: accumulate lengths yourself and split the vector array into multiple sends before exceeding Integer.MAX_VALUE.
  2. Reduce per-vector lengths; send oversized payloads in chunks via multiple publications.
  3. Audit the loop that builds the vectors for double-counting of length values.

Example fix

// before
offer(vectors); // may overflow int
// after
long total = 0;
int split = 0;
for (int i = 0; i < vectors.length; i++) {
    total += vectors[i].length;
    if (total > Integer.MAX_VALUE) { offer(Arrays.copyOfRange(vectors, split, i)); split = i; total = vectors[i].length; }
}
Defensive patterns

Strategy: validation

Validate before calling

long total = 0;
for (DirectBufferVector v : vectors) { total += v.length; }
if (total > Integer.MAX_VALUE) { throw new IllegalArgumentException("batch too large: " + total); }

Type guard

null

Try / catch

try {
    publication.offer(vectors);
} catch (IllegalStateException e) {
    log.error("vector batch exceeds 2GB int limit", e);
    splitAndResend(vectors);
}

Prevention

When it happens

Trigger: Calling a vectored publish/offer with enough vectors that sum(vectors[i].length) exceeds Integer.MAX_VALUE, causing int overflow to a negative value. Requires very large individual vectors or an enormous number of vectors.

Common situations: Batching many large messages into a single vectored write without a size budget; a bug where lengths are double-counted in an accumulation loop; passing the same large buffer repeatedly in the vector array.

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 aeron-io/aeron@6d60124e15 (2026-09-12). Data as JSON: /api/errors/9773ba8c3b6a892d. Report an issue: GitHub.

Appendix: source

Thrown at aeron-client/src/main/java/io/aeron/DirectBufferVector.java:188

    }

    /**
     * Validate an array of vectors to make up a message and compute the total length.
     *
     * @param vectors to be validated summed.
     * @return the sum of the vector lengths.
     */
    public static int validateAndComputeLength(final DirectBufferVector[] vectors)
    {
        int messageLength = 0;
        for (final DirectBufferVector vector : vectors)
        {
            vector.validate();
            messageLength += vector.length;

            if (messageLength < 0)
            {
                throw new IllegalStateException("length overflow: " + Arrays.toString(vectors));
            }
        }

        return messageLength;
    }
}

View on GitHub (pinned to 6d60124e15)