apache/iceberg · error · LockException
Interrupted while creating lock on table %s.%s
Error message
Interrupted while creating lock on table %s.%s
What it means
MetastoreLock uses Tasks.foreach with retries to run the create-lock loop; if the thread is interrupted while (re)issuing the lock request (checkLock/wait) call, the code restores the interrupt flag and throws this LockException wrapping the InterruptedException. Like error 2123, it means lock creation was aborted by interruption, not by metastore state.
Source
Thrown at hive-metastore/src/main/java/org/apache/iceberg/hive/MetastoreLock.java:344
Thread.currentThread().interrupt();
interrupted.set(true);
LOG.warn(
"Interrupted while trying to find lock for table {}.{}",
databaseName,
tableName,
e);
throw new LockException(
e,
"Interrupted while trying to find lock for table %s.%s",
databaseName,
tableName);
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
interrupted.set(true);
LOG.warn(
"Interrupted while creating lock on table {}.{}", databaseName, tableName, e);
throw new LockException(
e, "Interrupted while creating lock on table %s.%s", databaseName, tableName);
}
},
LockException.class);
// This should be initialized always, or exception should be thrown.
LOG.debug("Lock {} created for table {}.{}", lockInfo, databaseName, tableName);
return lockInfo;
}
/**
* Search for the locks using HMSClient.showLocks identified by the agentInfo. If the lock is
* there, then a {@link LockInfo} object is returned. If the lock is not found <code>null</code>
* is returned.
*
* @return The {@link LockInfo} for the found lock, or <code>null</code> if nothing found
*/
private LockInfo findLock() throws LockException, InterruptedException {View on GitHub (pinned to 86d9c8fc54)
Solutions
- Eliminate the interruption source (don't shutdownNow while commits are in flight; drain first).
- Reduce lock contention so the create-lock wait is short and less exposed to cancellation.
- Retry the commit after the interrupt clears; note the thread's interrupt flag is re-set by this code.
- Wrap commit calls in a retry policy that tolerates LockException caused by interruption during shutdown only if the commit is safe to re-run (Iceberg commits are).
Example fix
// before future.cancel(true); // interrupts commit thread mid-lock // after future.cancel(false); // or wait for commit completion before cancelling
Defensive patterns
Strategy: retry
Validate before calling
if (Thread.currentThread().isInterrupted()) {
throw new CancellationException("Skipping commit; thread interrupted");
} Try / catch
try {
table.commit(apply);
} catch (LockException e) {
if (e.getCause() instanceof InterruptedException) {
Thread.currentThread().interrupt();
throw new CancellationException("Commit interrupted during lock creation");
}
throw e;
} Prevention
- Shield commit threads from cancellation (Spark: don't kill the task holding the commit)
- Reduce lock contention so create-lock waits are short
- Drain executors gracefully before shutdown
- Treat interruption as cancellation, not a metastore error, in retry policies
When it happens
Trigger: Calling commit on a Hive-catalog table when the thread is interrupted inside the metastore checkLock heartbeat/wait RPC within the Tasks retry loop — executor shutdown, query cancellation, or Future.cancel(true).
Common situations: Long lock waits (contended table) being cancelled mid-wait; Spark/Flink job cancellation interrupting the committing task; JVM shutdown hooks interrupting background commit threads.
Related errors
- Interrupted while trying to find lock for table %s.%s
- Interrupted during commit
- Hive lock heartbeat thread not active
- Interrupted finding locks to unlock {}.{}
- Interrupted in SQL query
AI-assisted analysis of apache/iceberg@86d9c8fc54 (2026-09-12).
Data as JSON: /api/errors/715657d16194722c.
Report an issue: GitHub.