{"record":{"id":"16862b44694db3bc","repo":"apache/hadoop","slug":"interrupted-while-getting-the-last-block-length","errorCode":null,"errorMessage":"Interrupted while getting the last block length.","messagePattern":"Interrupted while getting the last block 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":281,"sourceCode":"  }\n\n  /**\n   * Set locatedBlocks and related fields, using the passed lastBlockLength.\n   * Should be called within infoLock.\n   */\n  private void setLocatedBlocksFields(LocatedBlocks locatedBlocksToSet, long lastBlockLength) {\n    locatedBlocks = locatedBlocksToSet;\n    lastBlockBeingWrittenLength = lastBlockLength;\n    fileEncryptionInfo = locatedBlocks.getFileEncryptionInfo();\n    setLastRefreshedBlocksAt();\n  }\n\n  private void waitFor(int waitTime) throws IOException {\n    try {\n      Thread.sleep(waitTime);\n    } catch (InterruptedException e) {\n      Thread.currentThread().interrupt();\n      throw new InterruptedIOException(\n          \"Interrupted while getting the last block length.\");\n    }\n  }\n\n  private LocatedBlocks fetchAndCheckLocatedBlocks(LocatedBlocks existing)\n      throws IOException {\n    LocatedBlocks newInfo = dfsClient.getLocatedBlocks(src, 0);\n\n    DFSClient.LOG.debug(\"newInfo = {}\", newInfo);\n    if (newInfo == null) {\n      throw new IOException(\"Cannot open filename \" + src);\n    }\n\n    if (existing != null) {\n      Iterator<LocatedBlock> oldIter =\n          existing.getLocatedBlocks().iterator();\n      Iterator<LocatedBlock> newIter = newInfo.getLocatedBlocks().iterator();\n      while (oldIter.hasNext() && newIter.hasNext()) {","sourceCodeStart":263,"sourceCodeEnd":299,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/DFSInputStream.java#L263-L299","documentation":"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.","triggerScenarios":"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).","commonSituations":"MapReduce/Spark task cancellation killing reader threads mid-open; application shutdown hooks interrupting worker pools; framework timeouts that interrupt rather than close streams.","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"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":"static boolean isCancelled(IOException e) {\n  return e instanceof InterruptedIOException;\n}","tryCatchPattern":"try {\n  in = fs.open(path);\n} catch (InterruptedIOException e) {\n  // thread cancelled mid-open: abort the task, never retry here\n  throw new java.util.concurrent.CancellationException(\"open interrupted\", e);\n}","preventionTips":["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()"],"tags":["hdfs","interrupt","open","concurrency"],"backgroundTag":"thread-interrupted","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}