{"record":{"id":"715657d16194722c","repo":"apache/iceberg","slug":"interrupted-while-creating-lock-on-table-s-s","errorCode":null,"errorMessage":"Interrupted while creating lock on table %s.%s","messagePattern":"Interrupted while creating lock on table (.+?)\\.(.+?)","errorType":"exception","errorClass":"LockException","httpStatus":null,"severity":"error","filePath":"hive-metastore/src/main/java/org/apache/iceberg/hive/MetastoreLock.java","lineNumber":344,"sourceCode":"                  Thread.currentThread().interrupt();\n                  interrupted.set(true);\n                  LOG.warn(\n                      \"Interrupted while trying to find lock for table {}.{}\",\n                      databaseName,\n                      tableName,\n                      e);\n                  throw new LockException(\n                      e,\n                      \"Interrupted while trying to find lock for table %s.%s\",\n                      databaseName,\n                      tableName);\n                }\n              } catch (InterruptedException e) {\n                Thread.currentThread().interrupt();\n                interrupted.set(true);\n                LOG.warn(\n                    \"Interrupted while creating lock on table {}.{}\", databaseName, tableName, e);\n                throw new LockException(\n                    e, \"Interrupted while creating lock on table %s.%s\", databaseName, tableName);\n              }\n            },\n            LockException.class);\n\n    // This should be initialized always, or exception should be thrown.\n    LOG.debug(\"Lock {} created for table {}.{}\", lockInfo, databaseName, tableName);\n    return lockInfo;\n  }\n\n  /**\n   * Search for the locks using HMSClient.showLocks identified by the agentInfo. If the lock is\n   * there, then a {@link LockInfo} object is returned. If the lock is not found <code>null</code>\n   * is returned.\n   *\n   * @return The {@link LockInfo} for the found lock, or <code>null</code> if nothing found\n   */\n  private LockInfo findLock() throws LockException, InterruptedException {","sourceCodeStart":326,"sourceCodeEnd":362,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/hive-metastore/src/main/java/org/apache/iceberg/hive/MetastoreLock.java#L326-L362","documentation":"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.","triggerScenarios":"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).","commonSituations":"Long lock waits (contended table) being cancelled mid-wait; Spark/Flink job cancellation interrupting the committing task; JVM shutdown hooks interrupting background commit threads.","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)."],"exampleFix":"// before\nfuture.cancel(true); // interrupts commit thread mid-lock\n// after\nfuture.cancel(false); // or wait for commit completion before cancelling","handlingStrategy":"retry","validationCode":"if (Thread.currentThread().isInterrupted()) {\n  throw new CancellationException(\"Skipping commit; thread interrupted\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  table.commit(apply);\n} catch (LockException e) {\n  if (e.getCause() instanceof InterruptedException) {\n    Thread.currentThread().interrupt();\n    throw new CancellationException(\"Commit interrupted during lock creation\");\n  }\n  throw e;\n}","preventionTips":["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"],"tags":["interruption","threading","hive","locking"],"backgroundTag":"thread-interrupted","analyzedSha":"86d9c8fc543e7c56c9f624eb725f76c9baff9570","analyzedAt":"2026-09-12T00:46:39.097Z","contentChangedAt":"2026-09-12T00:46:39.097Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}