{"record":{"id":"27e421203ea55c62","repo":"apache/iceberg","slug":"interrupted-during-trylock-27e421","errorCode":null,"errorMessage":"Interrupted during tryLock","messagePattern":"Interrupted during tryLock","errorType":"exception","errorClass":"UncheckedInterruptedException","httpStatus":null,"severity":"info","filePath":"flink/v2.1/flink/src/main/java/org/apache/iceberg/flink/maintenance/api/JdbcLockFactory.java","lineNumber":199,"sourceCode":"      try {\n        return pool.run(\n            conn -> {\n              try (PreparedStatement sql = conn.prepareStatement(CREATE_LOCK_SQL)) {\n                sql.setString(1, type.key);\n                sql.setString(2, lockId);\n                sql.setString(3, newInstanceId);\n                int count = sql.executeUpdate();\n                LOG.info(\n                    \"Created {} lock with instanceId {} with row count {}\",\n                    this,\n                    newInstanceId,\n                    count);\n                return count == 1;\n              }\n            });\n      } catch (InterruptedException e) {\n        Thread.currentThread().interrupt();\n        throw new UncheckedInterruptedException(e, \"Interrupted during tryLock\");\n      } catch (SQLException e) {\n        // SQL exception happened when creating the lock. Check if the lock creation was\n        // successful behind the scenes.\n        if (newInstanceId.equals(instanceId())) {\n          return true;\n        } else {\n          throw new UncheckedSQLException(e, \"Failed to create %s lock\", this);\n        }\n      }\n    }\n\n    @SuppressWarnings(\"checkstyle:NestedTryDepth\")\n    @Override\n    public boolean isHeld() {\n      try {\n        return pool.run(\n            conn -> {\n              try (PreparedStatement sql = conn.prepareStatement(GET_LOCK_SQL)) {","sourceCodeStart":181,"sourceCodeEnd":217,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/flink/v2.1/flink/src/main/java/org/apache/iceberg/flink/maintenance/api/JdbcLockFactory.java#L181-L217","documentation":"Thrown by JdbcLock.tryLock when the thread is interrupted while attempting to insert the lock row (acquire the maintenance lock) via the JDBC connection pool. The interrupt flag is restored and the exception is rethrown unchecked. The lock acquisition did not complete.","triggerScenarios":"tryLock is invoked while the executing thread (Flink task thread or scheduler thread) receives an interrupt — e.g. task cancellation, thread pool shutdown during lock contention.","commonSituations":"Flink cancels the maintenance task while it waits on a contended lock insert; application shutdown while the lock is being acquired; executor service shutdown in embedded usage.","solutions":["Expected during job/task cancellation — verify shutdown was intentional","If unexpected, find what interrupted the thread (executor shutdown, Flink cancel) and adjust lifecycle management","Reduce lock contention so tryLock completes quickly (shorter maintenance windows, fewer concurrent triggers)","After catching, ensure the interrupt flag is respected and do not loop retrying while interrupted"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  lock.tryLock();\n} catch (UncheckedInterruptedException e) {\n  Thread.currentThread().interrupt();\n  // task is shutting down; do not retry while interrupted\n}","preventionTips":["Ensure only one maintenance instance runs per table to shorten lock waits","Avoid shutdownNow() on executor threads that may hold or acquire maintenance locks","Monitor lock contention; long tryLock windows increase interrupt exposure"],"tags":["interrupted","locking","jdbc","flink","threading"],"backgroundTag":"operation-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"}