{"record":{"id":"224f87aaef881cf5","repo":"apache/iceberg","slug":"interrupted-while-trying-to-find-lock-for-table-s","errorCode":null,"errorMessage":"Interrupted while trying to find lock for table %s.%s","messagePattern":"Interrupted while trying to find lock for table (.+?)\\.(.+?)","errorType":"exception","errorClass":"LockException","httpStatus":null,"severity":"error","filePath":"hive-metastore/src/main/java/org/apache/iceberg/hive/MetastoreLock.java","lineNumber":333,"sourceCode":"                    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              }\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);","sourceCodeStart":315,"sourceCodeEnd":351,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/hive-metastore/src/main/java/org/apache/iceberg/hive/MetastoreLock.java#L315-L351","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nexecutor.shutdownNow(); // interrupts in-flight commit threads\n// after\nexecutor.shutdown();\nexecutor.awaitTermination(5, TimeUnit.MINUTES); // let commits finish before forcing shutdown","handlingStrategy":"try-catch","validationCode":"if (Thread.currentThread().isInterrupted()) {\n  throw new CancellationException(\"Refusing to commit on interrupted thread\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  table.commit(apply);\n} catch (LockException e) {\n  if (e.getCause() instanceof InterruptedException) {\n    Thread.currentThread().interrupt(); // preserve flag; treat as cancellation\n    return;\n  }\n  throw e;\n}","preventionTips":["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"],"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"}