{"record":{"id":"cbd4ba13111aeacd","repo":"apache/iceberg","slug":"interrupted-while-connecting-to-zookeeper-cbd4ba","errorCode":null,"errorMessage":"Interrupted while connecting to Zookeeper","messagePattern":"Interrupted while connecting to Zookeeper","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"flink/v2.2/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/v2.2/flink/src/main/java/org/apache/iceberg/flink/maintenance/api/ZkLockFactory.java#L119-L155","documentation":"ZkLockFactory.open() throws RuntimeException(\"Interrupted while connecting to Zookeeper\") if the thread is interrupted while waiting for the Curator client to connect (blockUntilConnected). The interrupt flag is restored before throwing, so callers can observe cancellation. This usually means the enclosing task was cancelled during startup.","triggerScenarios":"open() blocks in client.blockUntilConnected(...) waiting for the ZK session and the executing thread is interrupted (Flink task cancel, job restart, executor shutdown).","commonSituations":"User cancels a job that is stuck connecting to an unreachable ZooKeeper; deployment rollouts cancelling tasks mid-startup; a watchdog interrupting threads that hang on a bad ZK address.","solutions":["Fix the underlying connectivity problem that made the connect step slow enough to be interrupted (see the ZK address/port/ensemble).","Increase connectionTimeoutMs so startup completes quickly instead of lingering until cancelled.","If the interrupt is expected (job cancel), treat this as normal cancellation and restore the interrupt flag in your caller.","Check rollout/restart logs to correlate the interruption with job cancellation events."],"exampleFix":"// before\nThread.currentThread().interrupt(); // swallowed in user code, job loop spins\n// after\ntry {\n  lockFactory.open();\n} catch (RuntimeException e) {\n  if (e.getCause() instanceof InterruptedException) {\n    Thread.currentThread().interrupt(); // honor cancellation\n    return;\n  }\n  throw e;\n}","handlingStrategy":"try-catch","validationCode":"if (Thread.currentThread().isInterrupted()) { /* skip ZK connect */ }","typeGuard":null,"tryCatchPattern":"try { lockFactory.open(); } catch (RuntimeException e) { if (e.getCause() instanceof InterruptedException) { Thread.currentThread().interrupt(); return; } throw e; }","preventionTips":["Fix ZK connectivity so blockUntilConnected returns quickly.","Increase connectionTimeoutMs to finish startup before external interrupts.","Correlate interruption logs with job cancellations/rollouts.","Always restore the interrupt flag after catching this error."],"tags":["zookeeper","interrupted","flink","lock","startup"],"backgroundTag":"thread-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"}