{"record":{"id":"7612f3224fb48260","repo":"apache/hadoop","slug":"interrupted-while-getting-the-length","errorCode":null,"errorMessage":"Interrupted while getting the length.","messagePattern":"Interrupted while getting the length\\.","errorType":"exception","errorClass":"InterruptedIOException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/DFSInputStream.java","lineNumber":394,"sourceCode":"      }\n\n      // Ran out of nodes, but there are retriable nodes.\n      if (nodeList.size() == 0 && retryList.size() > 0) {\n        nodeList.addAll(retryList);\n        retryList.clear();\n        isRetry = true;\n      }\n\n      if (isRetry) {\n        // start the stop watch if not already running.\n        if (!sw.isRunning()) {\n          sw.start();\n        }\n        try {\n          Thread.sleep(500); // delay between retries.\n        } catch (InterruptedException e) {\n          Thread.currentThread().interrupt();\n          throw new InterruptedIOException(\n              \"Interrupted while getting the length.\");\n        }\n      }\n\n      // see if we ran out of retry time\n      if (sw.isRunning() && sw.now(TimeUnit.MILLISECONDS) > timeout) {\n        break;\n      }\n    }\n\n    // Namenode told us about these locations, but none know about the replica\n    // means that we hit the race between pipeline creation start and end.\n    // we require all 3 because some other exception could have happened\n    // on a DN that has it.  we want to report that error\n    if (replicaNotFoundCount == 0) {\n      return 0;\n    }\n","sourceCodeStart":376,"sourceCodeEnd":412,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/DFSInputStream.java#L376-L412","documentation":"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.","triggerScenarios":"Thread interrupt (shutdownNow, Future.cancel(true), container preemption) while the client is retrying DN length queries for a file under construction.","commonSituations":"Speculative-execution killers interrupting readers of open files; YARN container preemption; test harnesses that interrupt worker threads to unblock.","solutions":["Propagate InterruptedIOException as task cancellation; do not retry inside the same thread","Cancel readers by closing the stream/FileSystem rather than interrupting the thread","Audit executors that call shutdownNow() while HDFS reads are in flight"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":"static boolean isCancelled(IOException e) {\n  return e instanceof InterruptedIOException;\n}","tryCatchPattern":"try {\n  int n = in.read(buf);\n} catch (InterruptedIOException e) {\n  // cancellation: unwind, preserve interrupt flag (already set by HDFS)\n  throw new java.util.concurrent.CancellationException(\"read interrupted\", e);\n}","preventionTips":["Cancel readers by closing the stream, not by interrupting threads","Keep interruption for shutdown paths only, never for per-request timeouts on HDFS reads"],"tags":["hdfs","interrupt","block-length","concurrency"],"backgroundTag":"thread-interrupted","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}