apache/hadoop · error · InterruptedIOException
Interrupted while getting the last block length.
Error message
Interrupted while getting the last block length.
What it means
Raised from waitFor(), which sleeps between 'get last block length' retries during open. If the reading thread is interrupted during that sleep, the InterruptedException is converted into an InterruptedIOException after re-asserting the thread's interrupt flag. The open of the file is aborted; this is a cancellation signal, not an HDFS fault.
Source
Thrown at hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/DFSInputStream.java:281
}
/**
* Set locatedBlocks and related fields, using the passed lastBlockLength.
* Should be called within infoLock.
*/
private void setLocatedBlocksFields(LocatedBlocks locatedBlocksToSet, long lastBlockLength) {
locatedBlocks = locatedBlocksToSet;
lastBlockBeingWrittenLength = lastBlockLength;
fileEncryptionInfo = locatedBlocks.getFileEncryptionInfo();
setLastRefreshedBlocksAt();
}
private void waitFor(int waitTime) throws IOException {
try {
Thread.sleep(waitTime);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new InterruptedIOException(
"Interrupted while getting the last block length.");
}
}
private LocatedBlocks fetchAndCheckLocatedBlocks(LocatedBlocks existing)
throws IOException {
LocatedBlocks newInfo = dfsClient.getLocatedBlocks(src, 0);
DFSClient.LOG.debug("newInfo = {}", newInfo);
if (newInfo == null) {
throw new IOException("Cannot open filename " + src);
}
if (existing != null) {
Iterator<LocatedBlock> oldIter =
existing.getLocatedBlocks().iterator();
Iterator<LocatedBlock> newIter = newInfo.getLocatedBlocks().iterator();
while (oldIter.hasNext() && newIter.hasNext()) {View on GitHub (pinned to 2add963021)
Solutions
- Treat InterruptedIOException as cancellation: stop the reader task cleanly instead of retrying
- Cancel in-flight opens by closing the FileSystem / stream, not by interrupting the thread
- Make sure your executor honors interruption only at task boundaries when open() is in progress
Defensive patterns
Strategy: try-catch
Type guard
static boolean isCancelled(IOException e) {
return e instanceof InterruptedIOException;
} Try / catch
try {
in = fs.open(path);
} catch (InterruptedIOException e) {
// thread cancelled mid-open: abort the task, never retry here
throw new java.util.concurrent.CancellationException("open interrupted", e);
} Prevention
- Never interrupt threads performing HDFS opens/reads; cancel by closing streams
- Check Thread.currentThread().isInterrupted() at task boundaries instead of mid-call
- Isolate HDFS IO in executors you do not shut down with shutdownNow()
When it happens
Trigger: Thread.interrupt(), ExecutorService.shutdownNow(), or Future.cancel(true) hitting a thread currently inside FileSystem.open() on a file being written (the retry-sleep path is only entered when last-block length is unknown).
Common situations: MapReduce/Spark task cancellation killing reader threads mid-open; application shutdown hooks interrupting worker pools; framework timeouts that interrupt rather than close streams.
Related errors
- Interrupted while getting the length.
- Interrupted while waiting for reading task
- Interrupted while copying objects (copy)
- Another {name} is running.
- Commit or complete block {commitBlock}, whereas it is under
AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22).
Data as JSON: /api/errors/16862b44694db3bc.
Report an issue: GitHub.