apache/flink · error · EOFException

Could not skip {numBytes} bytes.

Error message

Could not skip {numBytes} bytes.

What it means

Thrown by DataInputDeserializer.skipBytesToRead(int) when skipBytes(numBytes) returned fewer bytes than requested, i.e. the read position hit this.end before advancing numBytes. It is a hard EOF error (unlike skipBytes which silently clamps).

Source

Thrown at flink-core/src/main/java/org/apache/flink/core/memory/DataInputDeserializer.java:377

    @Override
    public int skipBytes(int n) {
        if (this.position <= this.end - n) {
            this.position += n;
            return n;
        } else {
            n = this.end - this.position;
            this.position = this.end;
            return n;
        }
    }

    @Override
    public void skipBytesToRead(int numBytes) throws IOException {
        int skippedBytes = skipBytes(numBytes);

        if (skippedBytes < numBytes) {
            throw new EOFException("Could not skip " + numBytes + " bytes.");
        }
    }

    @Override
    public int read(@Nonnull byte[] b, int off, int len) throws IOException {

        if (off < 0) {
            throw new IndexOutOfBoundsException("Offset cannot be negative.");
        }

        if (len < 0) {
            throw new IndexOutOfBoundsException("Length cannot be negative.");
        }

        if (b.length - off < len) {
            throw new IndexOutOfBoundsException(
                    "Byte array does not provide enough space to store requested data" + ".");
        }

View on GitHub (pinned to 2f3c205e92)

Solutions

  1. Check available() >= numBytes before skipBytesToRead.
  2. Verify the read order matches the write order of the serializer.
  3. Ensure the buffer contains the complete record before deserialization begins.

Example fix

// before
input.skipBytesToRead(padding);

// after
if (input.available() >= padding) {
    input.skipBytesToRead(padding);
} else {
    throw new EOFException("Record truncated; only " + input.available() + " bytes left");
}
Defensive patterns

Strategy: validation

Validate before calling

if (input.available() < numBytes) {
    throw new EOFException("Need " + numBytes + " bytes, only " + input.available() + " available");
}
input.skipBytesToRead(numBytes);

Prevention

When it happens

Trigger: Calling skipBytesToRead(n) when fewer than n bytes remain between position and end (available() < n).

Common situations: Deserializing a record whose declared size exceeds the remaining buffer; reading fields in the wrong order so position overshoots; a buffer truncated after the record header; padding bytes that aren't actually present.

Related errors


AI-assisted analysis of apache/flink@2f3c205e92 (2026-08-14). Data as JSON: /api/errors/a22758ed9ea8c2ce. Report an issue: GitHub.