apache/flink · error · EOFException
Could not skip {numBytes} bytes.
Error message
Could not skip {numBytes} bytes. What it means
Thrown by DataInputViewStreamWrapper.skipBytesToRead(int) when the underlying InputStream's skipBytes returned fewer bytes than requested, i.e. the stream reached EOF before numBytes could be skipped. This wrapper adapts a blocking InputStream to the DataInputView contract and treats a short skip as a hard EOF.
Source
Thrown at flink-core/src/main/java/org/apache/flink/core/memory/DataInputViewStreamWrapper.java:39
import org.apache.flink.annotation.PublicEvolving;
import java.io.DataInputStream;
import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;
/** Utility class that turns an {@link InputStream} into a {@link DataInputView}. */
@PublicEvolving
public class DataInputViewStreamWrapper extends DataInputStream implements DataInputView {
public DataInputViewStreamWrapper(InputStream in) {
super(in);
}
@Override
public void skipBytesToRead(int numBytes) throws IOException {
if (skipBytes(numBytes) != numBytes) {
throw new EOFException("Could not skip " + numBytes + " bytes.");
}
}
}
View on GitHub (pinned to 2f3c205e92)
Solutions
- Confirm the stream contains at least numBytes before skipping (e.g. via available() or a known message length).
- Ensure the source stream is fully buffered/complete before deserialization.
- Handle EOFException to detect truncation at the framing layer.
Example fix
// before
view.skipBytesToRead(fieldSize);
// after
try {
view.skipBytesToRead(fieldSize);
} catch (EOFException e) {
throw new IOException("Stream truncated while skipping field of " + fieldSize + " bytes", e);
} Defensive patterns
Strategy: try-catch
Validate before calling
// Best-effort: check stream availability before skipping
if (in.available() > 0 && in.available() < numBytes) {
throw new EOFException("Stream has only " + in.available() + " bytes, need " + numBytes);
} Try / catch
try {
view.skipBytesToRead(numBytes);
} catch (EOFException e) {
throw new IOException("Input stream truncated before " + numBytes + " bytes could be skipped", e);
} Prevention
- Ensure the source stream is complete before wrapping it for deserialization.
- Frame messages with an explicit length and validate it against the stream before skipping.
- Handle EOFException at the framing layer to detect truncation cleanly.
When it happens
Trigger: Calling skipBytesToRead(n) on a DataInputViewStreamWrapper whose backing InputStream has fewer than n bytes remaining (or returns -1).
Common situations: Truncated network stream or file; closed/drained input stream; a record header declaring more skip bytes than the payload contains; reading past the end of a fixed-size message.
Related errors
- Reached the end of the collection. This could be caused by i
- Could not skip {numBytes} bytes.
- Failed to deserialize an element from the source. If you are
- Failed to deserialize an element from the source. If you are
- Unable to deserialize message
AI-assisted analysis of apache/flink@2f3c205e92 (2026-08-14).
Data as JSON: /api/errors/0d12f88e02b433f4.
Report an issue: GitHub.