{"record":{"id":"6a2482391b749f05","repo":"apache/hadoop","slug":"cannot-open-filename-6a2482","errorCode":null,"errorMessage":"Cannot open filename {}","messagePattern":"Cannot open filename (.+?)","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/DFSInputStream.java","lineNumber":292,"sourceCode":"  }\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()) {\n        if (!oldIter.next().getBlock().equals(newIter.next().getBlock())) {\n          throw new IOException(\"Blocklist for \" + src + \" has changed!\");\n        }\n      }\n    }\n\n    return newInfo;\n  }\n\n  private long getLastBlockLength(LocatedBlocks blocks) throws IOException{\n    long lastBlockBeingWrittenLength = 0;","sourceCodeStart":274,"sourceCodeEnd":310,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/DFSInputStream.java#L274-L310","documentation":"fetchAndCheckLocatedBlocks() treats a null result from dfsClient.getLocatedBlocks(src, 0) as fatal. The NameNode returned no block metadata for the path at all, which in practice means the file vanished (deleted or renamed) between open and the located-blocks RPC, or the RPC landed on a Standby/Router NameNode that yielded null instead of a proper error.","triggerScenarios":"openInfo()/openInfo(true) refresh racing a delete or rename of src; HA misconfiguration where every RPC goes to a standby NameNode; HDFS Router federation routing the path to the wrong subcluster.","commonSituations":"Reading temp/part files that a cleaner process removes concurrently; retrying reads after a file was overwritten by delete+recreate; wrong dfs.ha.namenodes.<id> addresses so the client only ever reaches standby NNs.","solutions":["Verify the path still exists (fs.exists / getFileStatus) and re-resolve it before retrying","Check HA configuration: dfs.nameservices, dfs.ha.namenodes.<ns>, and the failover proxy provider settings","If using HDFS Router, verify the mount table maps the path to a subcluster that owns it","Coordinate producers/consumers so files are not deleted while being opened"],"exampleFix":"// before\nFSDataInputStream in = fs.open(path);\n\n// after: confirm the file exists right before opening\nif (!fs.exists(path)) throw new FileNotFoundException(path.toString());\ntry (FSDataInputStream in = fs.open(path)) { /* read */ }","handlingStrategy":"validation","validationCode":"if (!fs.exists(path)) {\n  throw new FileNotFoundException(path.toString());\n}\ntry (FSDataInputStream in = fs.open(path)) { /* read */ }","typeGuard":"static boolean isFileVanished(IOException e) {\n  return e.getMessage() != null && e.getMessage().startsWith(\"Cannot open filename\");\n}","tryCatchPattern":"try {\n  in = fs.open(path);\n} catch (IOException e) {\n  if (isFileVanished(e)) { /* re-resolve path or skip */ }\n  else throw e;\n}","preventionTips":["Stat the file immediately before opening when deletions can race","Coordinate producers/consumers so files are not removed while being read","Verify HA nameservice and router mount configuration so RPCs reach an active NN"],"tags":["hdfs","open","file-not-found","name-node","ha"],"backgroundTag":"file-not-found","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}