{"record":{"id":"114fca70e2d82f6e","repo":"apache/iceberg","slug":"interrupted-while-creating-lock-on-table","errorCode":null,"errorMessage":"Interrupted while creating lock on table {}.{}","messagePattern":"Interrupted while creating lock on table (.+?)\\.(.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"hive-metastore/src/main/java/org/apache/iceberg/hive/MetastoreLock.java","lineNumber":342,"sourceCode":"                      \"Failed to find lock for table %s.%s\", databaseName, tableName);\n                } catch (InterruptedException e) {\n                  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","sourceCodeStart":324,"sourceCodeEnd":360,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/hive-metastore/src/main/java/org/apache/iceberg/hive/MetastoreLock.java#L324-L360","documentation":"MetastoreLock.createLock() issues the actual Hive lock-table creation call inside a retry block; if interrupted while creating the lock, the interrupt status is restored, this warning is logged, and a LockException (\"Interrupted while creating lock on table...\") propagates to the caller. The lock may or may not have been created in the metastore, so the caller should treat the transaction as not locked.","triggerScenarios":"The Hive client call that creates the lock (within the Tasks.retry body) throws InterruptedException because the calling thread was interrupted — usually during Flink job cancellation or executor shutdown.","commonSituations":"Application shutdown interrupting a commit in progress; thread-pool teardown while a write transaction is acquiring its Hive lock; long metastore RPCs making the lock call slow enough to overlap with cancellation.","solutions":["Retry the operation after determining whether a lock was actually created (check SHOW LOCKS for the table).","Avoid interrupting threads inside the Iceberg commit critical section; cancel only between transactions.","Handle the LockException by cleaning up any partially created lock before retrying.","Increase metastore RPC timeouts so lock creation completes before shutdown windows close."],"exampleFix":"// before: interrupting mid-commit\nexecutor.shutdownNow(); // interrupts in-flight lock creation\n// after: graceful shutdown\nexecutor.shutdown();\nexecutor.awaitTermination(5, TimeUnit.MINUTES);","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  lock.lock();\n} catch (LockException e) {\n  // check SHOW LOCKS for partially created lock, clean up, then retry\n}","preventionTips":["Avoid shutdownNow() while transactions are committing","Verify lock state after interrupted creation before retrying","Set generous metastore RPC timeouts"],"tags":["hive","lock-contention","interrupted","metastore"],"backgroundTag":"lock-wait-interrupted","analyzedSha":"86d9c8fc543e7c56c9f624eb725f76c9baff9570","analyzedAt":"2026-09-12T00:46:39.097Z","contentChangedAt":"2026-09-12T00:46:39.097Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}