apache/iceberg · error · LockException
Interrupted while trying to find lock for table %s.%s
Error message
Interrupted while trying to find lock for table %s.%s
What it means
While polling showLocks to confirm the newly created lock, the waiting thread can be interrupted. The code restores the interrupt flag, logs a warning with the cause, and rethrows as a LockException wrapping the InterruptedException. This signals the commit's lock acquisition was cancelled by thread interruption rather than a metastore problem.
Source
Thrown at hive-metastore/src/main/java/org/apache/iceberg/hive/MetastoreLock.java:333
if (lockFound != null) {
lockInfo.lockId = lockFound.lockId;
lockInfo.lockState = lockFound.lockState;
LOG.info("Found lock {} by agentInfo {}", lockInfo, agentInfo);
return;
}
}
throw new LockException(
"Failed to find lock for table %s.%s", databaseName, tableName);
} catch (InterruptedException e) {
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);View on GitHub (pinned to 86d9c8fc54)
Solutions
- Identify and remove the source of interruption (task cancellation, executor shutdown) before committing.
- Retry the commit from a non-interrupted thread; the interrupt flag is preserved so the caller must decide to retry.
- If committing in a thread pool, ensure shutdown/cancellation logic drains in-flight commits or shields commit threads from interruption.
- Check logs for the logged InterruptedException cause to find who interrupted the thread.
Example fix
// before executor.shutdownNow(); // interrupts in-flight commit threads // after executor.shutdown(); executor.awaitTermination(5, TimeUnit.MINUTES); // let commits finish before forcing shutdown
Defensive patterns
Strategy: try-catch
Validate before calling
if (Thread.currentThread().isInterrupted()) {
throw new CancellationException("Refusing to commit on interrupted thread");
} Try / catch
try {
table.commit(apply);
} catch (LockException e) {
if (e.getCause() instanceof InterruptedException) {
Thread.currentThread().interrupt(); // preserve flag; treat as cancellation
return;
}
throw e;
} Prevention
- Don't call executor.shutdownNow() while commits are in flight; drain first
- Use Future.cancel(false) instead of cancel(true) for commit tasks
- Commit on dedicated threads insulated from query-cancellation interrupts
- Check e.getCause() instanceof InterruptedException to distinguish interruption from metastore failure
When it happens
Trigger: Calling commit on a Hive-catalog table from a thread that gets interrupted during the lock-acquisition polling loop — e.g. executor shutdown, task cancellation, or query kill (Spark/Flink cancel) interrupting worker threads.
Common situations: Spark stage cancellation or speculative-execution kills interrupting the commit thread; application shutdown (SIGTERM to the executor) interrupting scheduler threads; manual Future.cancel(true) on the commit task.
Related errors
- Interrupted while creating lock on 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/224f87aaef881cf5.
Report an issue: GitHub.