apache/hadoop · error · InterruptedIOException

Interrupted while getting the length.

Error message

Interrupted while getting the length.

What it means

Inside the loop that asks each DataNode for the length of the last block under construction, the client sleeps 500ms between retries. If the thread is interrupted during that sleep, the InterruptedException is converted to InterruptedIOException (interrupt flag restored) and the length fetch aborts. Cancellation semantics, not a data problem.

Source

Thrown at hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/DFSInputStream.java:394

      }

      // Ran out of nodes, but there are retriable nodes.
      if (nodeList.size() == 0 && retryList.size() > 0) {
        nodeList.addAll(retryList);
        retryList.clear();
        isRetry = true;
      }

      if (isRetry) {
        // start the stop watch if not already running.
        if (!sw.isRunning()) {
          sw.start();
        }
        try {
          Thread.sleep(500); // delay between retries.
        } catch (InterruptedException e) {
          Thread.currentThread().interrupt();
          throw new InterruptedIOException(
              "Interrupted while getting the length.");
        }
      }

      // see if we ran out of retry time
      if (sw.isRunning() && sw.now(TimeUnit.MILLISECONDS) > timeout) {
        break;
      }
    }

    // Namenode told us about these locations, but none know about the replica
    // means that we hit the race between pipeline creation start and end.
    // we require all 3 because some other exception could have happened
    // on a DN that has it.  we want to report that error
    if (replicaNotFoundCount == 0) {
      return 0;
    }

View on GitHub (pinned to 2add963021)

Solutions

  1. Propagate InterruptedIOException as task cancellation; do not retry inside the same thread
  2. Cancel readers by closing the stream/FileSystem rather than interrupting the thread
  3. Audit executors that call shutdownNow() while HDFS reads are in flight
Defensive patterns

Strategy: try-catch

Type guard

static boolean isCancelled(IOException e) {
  return e instanceof InterruptedIOException;
}

Try / catch

try {
  int n = in.read(buf);
} catch (InterruptedIOException e) {
  // cancellation: unwind, preserve interrupt flag (already set by HDFS)
  throw new java.util.concurrent.CancellationException("read interrupted", e);
}

Prevention

When it happens

Trigger: Thread interrupt (shutdownNow, Future.cancel(true), container preemption) while the client is retrying DN length queries for a file under construction.

Common situations: Speculative-execution killers interrupting readers of open files; YARN container preemption; test harnesses that interrupt worker threads to unblock.

Related errors


AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22). Data as JSON: /api/errors/7612f3224fb48260. Report an issue: GitHub.