apache/hadoop · error · AlreadyBeingCreatedException

Failed to {} {} for {} on {} because the file is under const

Error message

Failed to {} {} for {} on {} because the file is under construction but no leases found.

What it means

The file's INode still carries FileUnderConstructionFeature with a recorded clientName, but the LeaseManager has no live lease for that client — write state is inconsistent (UC feature persisted, lease gone). Re-opening therefore fails with AlreadyBeingCreatedException('the file is under construction but no leases found.')

Source

Thrown at hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java:2992

      if (!force && lease != null) {
        Lease leaseFile = leaseManager.getLease(file);
        if (leaseFile != null && leaseFile.equals(lease)) {
          // We found the lease for this file but the original
          // holder is trying to obtain it again.
          throw new AlreadyBeingCreatedException(
              op.getExceptionMessage(src, holder, clientMachine,
                  holder + " is already the current lease holder."));
        }
      }
      //
      // Find the original holder.
      //
      FileUnderConstructionFeature uc = file.getFileUnderConstructionFeature();
      String clientName = uc.getClientName();
      lease = leaseManager.getLease(clientName);
      if (lease == null) {
        throw new AlreadyBeingCreatedException(
            op.getExceptionMessage(src, holder, clientMachine,
                "the file is under construction but no leases found."));
      }
      if (force) {
        // close now: no need to wait for soft lease expiration and 
        // close only the file src
        LOG.info("recoverLease: " + lease + ", src=" + src +
          " from client " + clientName);
        return internalReleaseLease(lease, src, iip, holder);
      } else {
        assert lease.getHolder().equals(clientName) :
          "Current lease holder " + lease.getHolder() +
          " does not match file creator " + clientName;
        //
        // If the original holder has not renewed in the last SOFTLIMIT 
        // period, then start lease recovery.
        //
        if (lease.expiredSoftLimit()) {

View on GitHub (pinned to 2add963021)

Solutions

  1. Force closure: DistributedFileSystem#recoverLease(path) or `hdfs debug recoverLease -path <path>`, wait for isFileClosed(path), then re-create
  2. If the NameNode just failed over, wait briefly — lease reconstruction from the edit log often finalizes the file on its own
  3. If unrecoverable, move/delete the orphaned file (its data is incomplete anyway) and rewrite it

Example fix

// before
FSDataOutputStream out = fs.create(path, true);   // AlreadyBeingCreatedException: no leases found
// after
DistributedFileSystem dfs = (DistributedFileSystem) fs;
if (!dfs.isFileClosed(path)) { dfs.recoverLease(path); }
while (!dfs.isFileClosed(path)) { Thread.sleep(1000); }
FSDataOutputStream out = fs.create(path, true);
Defensive patterns

Strategy: try-catch

Validate before calling

DistributedFileSystem dfs = (DistributedFileSystem) fs;
if (!dfs.isFileClosed(path)) { dfs.recoverLease(path); /* wait for isFileClosed before re-create */ }

Try / catch

catch (AlreadyBeingCreatedException e) { if (e.getMessage() != null && e.getMessage().contains("no leases found")) { dfs.recoverLease(src); waitForFileClosed(dfs, src); retryCreate(); } else throw e; }

Prevention

When it happens

Trigger: startFile/create against an under-construction file whose owning lease disappeared — typically right after a NameNode failover/restart while lease tables are rebuilt from the edit log, or after lease-checkpoint edge cases.

Common situations: Writer process died and a NameNode failover followed; a retried job hits the orphaned under-construction file before the new NN finishes internal recovery; rare races between hard-limit lease monitor cleanup and re-opens.

Related errors


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