{"record":{"id":"88a02ac336a9b5b7","repo":"apache/iceberg","slug":"interrupted-while-trying-to-find-lock-for-table","errorCode":null,"errorMessage":"Interrupted while trying to find lock for table {}.{}","messagePattern":"Interrupted while trying to find lock for table (.+?)\\.(.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"hive-metastore/src/main/java/org/apache/iceberg/hive/MetastoreLock.java","lineNumber":328,"sourceCode":"                try {\n                  // If we can not check for lock, or we do not find it, then rethrow the exception\n                  // Otherwise we are happy as the findLock sets the lockId and the state correctly\n                  if (HiveVersion.min(HiveVersion.HIVE_2)) {\n                    LockInfo lockFound = findLock();\n                    if (lockFound != null) {\n                      lockInfo.lockId = lockFound.lockId;\n                      lockInfo.lockState = lockFound.lockState;\n                      LOG.info(\"Found lock {} by agentInfo {}\", lockInfo, agentInfo);\n                      return;\n                    }\n                  }\n\n                  throw new LockException(\n                      \"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              }","sourceCodeStart":310,"sourceCodeEnd":346,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/hive-metastore/src/main/java/org/apache/iceberg/hive/MetastoreLock.java#L310-L346","documentation":"MetastoreLock.createLock() queries Hive for the existing lock while polling; if that wait is interrupted, the thread's interrupt status is restored, this warning is logged, and a LockException (\"Interrupted while trying to find lock...\") is thrown so the caller knows lock acquisition failed due to interruption. Unlike 3406, this path aborts instead of retrying.","triggerScenarios":"The thread executing lockInfo()/createLock()'s retry loop is interrupted while sleeping between checks for the Hive lock's state, hitting the InterruptedException branch after 'Failed to find lock for table'.","commonSituations":"Flink job cancellation during commit; executor shutdown; Hive locks held long by other transactions causing waits long enough to be interrupted by timeouts or cancels.","solutions":["Identify the interruption source (job cancel/shutdown) and retry the commit operation in a fresh thread.","Release contending Hive locks (SHOW LOCKS, manual unlock) to shorten wait windows.","Keep commit operations out of cancellation paths; complete or abort the transaction before shutdown.","Clean up stale Hive locks from crashed sessions to reduce contention."],"exampleFix":"// before: swallowing the LockException\ntry { table.commit(); } catch (LockException e) { /* ignore */ }\n// after: surface and retry\ntry { table.commit(); } catch (LockException e) {\n  throw new RuntimeException(\"Commit lock failed for \" + tableName, e);\n}","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  lock.lock();\n} catch (LockException e) {\n  if (e.getCause() instanceof InterruptedException) {\n    Thread.currentThread().interrupt(); // preserve status, retry later\n  }\n}","preventionTips":["Use graceful cancellation so lock acquisition isn't interrupted mid-wait","Release contending Hive locks promptly","Clean up locks from crashed sessions"],"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"}