{"record":{"id":"d75eb8f47996c2f2","repo":"apache/iceberg","slug":"interrupted-while-waiting-for-lock-on-table","errorCode":null,"errorMessage":"Interrupted while waiting for lock on table {}.{}","messagePattern":"Interrupted while waiting for lock on table (.+?)\\.(.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"hive-metastore/src/main/java/org/apache/iceberg/hive/MetastoreLock.java","lineNumber":222,"sourceCode":"        Tasks.foreach(lockInfo.lockId)\n            .retry(Integer.MAX_VALUE - 100)\n            .exponentialBackoff(lockCheckMinWaitTime, lockCheckMaxWaitTime, lockAcquireTimeout, 1.5)\n            .throwFailureWhenFinished()\n            .onlyRetryOn(WaitingForLockException.class)\n            .run(\n                id -> {\n                  try {\n                    LockResponse response = metaClients.run(client -> client.checkLock(id));\n                    LockState newState = response.getState();\n                    lockInfo.lockState = newState;\n                    if (newState.equals(LockState.WAITING)) {\n                      throw new WaitingForLockException(\n                          String.format(\n                              \"Waiting for lock on table %s.%s\", databaseName, tableName));\n                    }\n                  } catch (InterruptedException e) {\n                    Thread.interrupted(); // Clear the interrupt status flag\n                    LOG.warn(\n                        \"Interrupted while waiting for lock on table {}.{}\",\n                        databaseName,\n                        tableName,\n                        e);\n                  }\n                },\n                TException.class);\n      }\n    } catch (WaitingForLockException e) {\n      timeout = true;\n      duration = System.currentTimeMillis() - start;\n    } catch (TException e) {\n      thriftError = e;\n    } finally {\n      if (!lockInfo.lockState.equals(LockState.ACQUIRED)) {\n        unlock(Optional.of(lockInfo.lockId));\n      }\n    }","sourceCodeStart":204,"sourceCodeEnd":240,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/hive-metastore/src/main/java/org/apache/iceberg/hive/MetastoreLock.java#L204-L240","documentation":"MetastoreLock.acquireLock() polls Hive's lock state in a loop, throwing WaitingForLockException on timeout and re-checking after backoff. If the polling thread is interrupted while sleeping/waiting, this warning is logged after clearing the interrupt flag, and the acquire loop continues waiting for the lock. It signals that a caller tried to interrupt a thread blocked waiting for a Hive table lock.","triggerScenarios":"Thread calling MetastoreLock.lock() is interrupted while the acquireLock retry loop is sleeping between Hive lock checks (inside the Tasks.retry body's InterruptedException handler).","commonSituations":"Flink/executor shutdown interrupting worker threads; job cancellation while a commit is waiting on a contended Hive lock; lock held by a stale/abandoned session blocking another query for a long time.","solutions":["Find and release the contending Hive lock (SHOW LOCKS / unlock via Hive) so acquisition completes quickly.","Investigate who interrupted the thread — typically job shutdown — and avoid interrupting during the commit critical section.","Reduce lock hold times / tune lock acquisition timeouts so waits are short.","Clean up stale locks left by crashed sessions (Hive LOCKS table maintenance)."],"exampleFix":"// before: interrupting the commit thread mid-lock-wait\ncommitThread.interrupt();\n// after: cancel after the transaction completes\ncommitThread.join();\ncommitThread.interrupt();","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  lock.lock();\n} catch (LockException | WaitingForLockException e) {\n  // retry after releasing contending locks\n}","preventionTips":["Monitor and clean stale Hive locks regularly","Don't interrupt threads inside the commit critical section","Keep lock hold durations short"],"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"}