apache/hadoop · error · AlreadyBeingCreatedException
Failed to {} {} for {} on {} because this file lease is curr
Error message
Failed to {} {} for {} on {} because this file lease is currently owned by {} on {} What it means
The file's lease is alive, held by a different client, and has not passed the soft limit, so pre-emption is refused: AlreadyBeingCreatedException('this file lease is currently owned by <client> on <machine>.') — HDFS enforces single-writer semantics until the holder's lease lapses, is released, or is recovered.
Source
Thrown at hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java:3029
LOG.info("startFile: recover " + lease + ", src=" + src + " client "
+ clientName);
if (internalReleaseLease(lease, src, iip, null)) {
return true;
} else {
throw new RecoveryInProgressException(
op.getExceptionMessage(src, holder, clientMachine,
"lease recovery is in progress. Try again later."));
}
} else {
final BlockInfo lastBlock = file.getLastBlock();
if (lastBlock != null
&& lastBlock.getBlockUCState() == BlockUCState.UNDER_RECOVERY) {
throw new RecoveryInProgressException(
op.getExceptionMessage(src, holder, clientMachine,
"another recovery is in progress by "
+ clientName + " on " + uc.getClientMachine()));
} else {
throw new AlreadyBeingCreatedException(
op.getExceptionMessage(src, holder, clientMachine,
"this file lease is currently owned by "
+ clientName + " on " + uc.getClientMachine()));
}
}
}
} else {
return true;
}
}
/**
* Append to an existing file in the namespace.
*/
LastBlockWithStatus appendFile(String srcArg, String holder,
String clientMachine, EnumSet<CreateFlag> flag, boolean logRetryCache)
throws IOException {
final String operationName = "append";View on GitHub (pinned to 2add963021)
Solutions
- Stop the current holder — its lease releases on clean close, or lapses at the soft limit after death — then retry
- If the holder is known-dead, call recoverLease(path): the NN recovers at/after the soft limit and closes the file; then append or re-create
- Adopt unique output paths plus atomic rename so two writers can never collide
Example fix
// before
FSDataOutputStream out = fs.create(path, true); // owned by another client
// after
DistributedFileSystem dfs = (DistributedFileSystem) fs;
if (!dfs.isFileClosed(path)) { dfs.recoverLease(path); }
while (!dfs.isFileClosed(path)) { Thread.sleep(5000L); }
FSDataOutputStream out = fs.append(path); // or fs.create(path, true) Defensive patterns
Strategy: try-catch
Validate before calling
DistributedFileSystem dfs = (DistributedFileSystem) fs;
if (!dfs.isFileClosed(path)) { dfs.recoverLease(path); /* recovers at/after the 60s soft limit */ } Try / catch
catch (AlreadyBeingCreatedException e) { if (e.getMessage() != null && e.getMessage().contains("currently owned by")) { dfs.recoverLease(src); waitForCloseThenAppend(); } else throw e; } Prevention
- Guarantee one writer per path via app-level locking or unique names
- Confirm old writers are dead before restarting writes to the same path
When it happens
Trigger: A second writer calls create/append on a file whose lease is being actively renewed by clientName from another machine, within dfs.namenode.lease-soft-limit-sec (default 60s) of the last renewal, with the last block not under recovery.
Common situations: Duplicate app instances pointed at the same output file; a stuck-but-alive previous writer still renewing; deployment scripts that restart a job while the old instance still heartbeats.
Related errors
- Failed to {} {} for {} on {} because {} is already the curre
- Client (={}) is not the lease owner (={}: {} (inode {}) {}
- <src> for client <clientMachine> already exists
- Lease mismatch: {} is accessed by a non lease holder {}
- Attempted to write to file without lease
AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22).
Data as JSON: /api/errors/74cda6784ab4d91f.
Report an issue: GitHub.