{"record":{"id":"802eec00b82492f2","repo":"apache/iceberg","slug":"interrupted-while-connecting-to-zookeeper","errorCode":null,"errorMessage":"Interrupted while connecting to Zookeeper","messagePattern":"Interrupted while connecting to Zookeeper","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"flink/v1.20/flink/src/main/java/org/apache/iceberg/flink/maintenance/api/ZkLockFactory.java","lineNumber":137,"sourceCode":"            .connectionTimeoutMs(connectionTimeoutMs)\n            .retryPolicy(createRetryPolicy())\n            .build();\n    client.start();\n\n    try {\n      if (!client.blockUntilConnected(connectionTimeoutMs, TimeUnit.MILLISECONDS)) {\n        throw new IllegalStateException(\"Connection to Zookeeper timed out\");\n      }\n\n      this.taskSharedCount = new SharedCount(client, getTaskSharePath(), 0);\n      this.recoverySharedCount = new SharedCount(client, getRecoverySharedPath(), 0);\n      taskSharedCount.start();\n      recoverySharedCount.start();\n      isOpen = true;\n      LOG.info(\"ZkLockFactory initialized for lockId: {}.\", lockId);\n    } catch (InterruptedException e) {\n      Thread.currentThread().interrupt();\n      throw new RuntimeException(\"Interrupted while connecting to Zookeeper\", e);\n    } catch (Exception e) {\n      closeQuietly();\n      throw new RuntimeException(\"Failed to initialize SharedCount\", e);\n    }\n  }\n\n  private String getTaskSharePath() {\n    return LOCK_BASE_PATH + lockId + \"/task\";\n  }\n\n  private String getRecoverySharedPath() {\n    return LOCK_BASE_PATH + lockId + \"/recovery\";\n  }\n\n  private void closeQuietly() {\n    try {\n      close();\n    } catch (Exception e) {","sourceCodeStart":119,"sourceCodeEnd":155,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/flink/v1.20/flink/src/main/java/org/apache/iceberg/flink/maintenance/api/ZkLockFactory.java#L119-L155","documentation":"ZkLockFactory.open() was interrupted while waiting for the Curator client to connect (blockUntilConnected) or starting the SharedCounts; the library restores the interrupt flag and throws RuntimeException('Interrupted while connecting to Zookeeper', e). ZooKeeper connection was not completed.","triggerScenarios":"Thread interrupted during open() while blocked in client.blockUntilConnected(...) — typically task cancellation or JVM shutdown during lock factory initialization.","commonSituations":"Flink cancels the maintenance trigger during startup; kill signals interrupt the connecting thread; job restart racing with slow ZooKeeper connect (cross-DC latency).","solutions":["Retry open() after the cancellation finishes; recreate the factory in a fresh thread.","Reduce ZooKeeper connect latency so initialization completes before any interrupt arrives.","Avoid shutting down/cancelling while lock initialization is in progress; sequence shutdown after open() returns.","Catch RuntimeException at the caller, check Thread.currentThread().isInterrupted(), and re-init if appropriate.","Log lockId on failure to trace which trigger needs re-initialization."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  factory.open();\n} catch (RuntimeException e) {\n  if (e.getCause() instanceof InterruptedException) {\n    Thread.currentThread().interrupt();\n    // re-open after cancellation settles\n  }\n}","preventionTips":["Sequence shutdown after lock init completes","Minimize ZK connect latency (local quorum, low RTT)","Avoid killing the JVM during factory initialization","Retry open() in a fresh thread after cancellation"],"tags":["flink","zookeeper","lock","interrupt"],"backgroundTag":"thread-interrupted","analyzedSha":"86d9c8fc543e7c56c9f624eb725f76c9baff9570","analyzedAt":"2026-09-12T00:46:39.097Z","contentChangedAt":"2026-09-12T00:46:39.097Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}