apache/iceberg · error · RuntimeException

Interrupted while connecting to Zookeeper

Error message

Interrupted while connecting to Zookeeper

What it means

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.

Source

Thrown at flink/v1.20/flink/src/main/java/org/apache/iceberg/flink/maintenance/api/ZkLockFactory.java:137

            .connectionTimeoutMs(connectionTimeoutMs)
            .retryPolicy(createRetryPolicy())
            .build();
    client.start();

    try {
      if (!client.blockUntilConnected(connectionTimeoutMs, TimeUnit.MILLISECONDS)) {
        throw new IllegalStateException("Connection to Zookeeper timed out");
      }

      this.taskSharedCount = new SharedCount(client, getTaskSharePath(), 0);
      this.recoverySharedCount = new SharedCount(client, getRecoverySharedPath(), 0);
      taskSharedCount.start();
      recoverySharedCount.start();
      isOpen = true;
      LOG.info("ZkLockFactory initialized for lockId: {}.", lockId);
    } catch (InterruptedException e) {
      Thread.currentThread().interrupt();
      throw new RuntimeException("Interrupted while connecting to Zookeeper", e);
    } catch (Exception e) {
      closeQuietly();
      throw new RuntimeException("Failed to initialize SharedCount", e);
    }
  }

  private String getTaskSharePath() {
    return LOCK_BASE_PATH + lockId + "/task";
  }

  private String getRecoverySharedPath() {
    return LOCK_BASE_PATH + lockId + "/recovery";
  }

  private void closeQuietly() {
    try {
      close();
    } catch (Exception e) {

View on GitHub (pinned to 86d9c8fc54)

Solutions

  1. Retry open() after the cancellation finishes; recreate the factory in a fresh thread.
  2. Reduce ZooKeeper connect latency so initialization completes before any interrupt arrives.
  3. Avoid shutting down/cancelling while lock initialization is in progress; sequence shutdown after open() returns.
  4. Catch RuntimeException at the caller, check Thread.currentThread().isInterrupted(), and re-init if appropriate.
  5. Log lockId on failure to trace which trigger needs re-initialization.
Defensive patterns

Strategy: try-catch

Try / catch

try {
  factory.open();
} catch (RuntimeException e) {
  if (e.getCause() instanceof InterruptedException) {
    Thread.currentThread().interrupt();
    // re-open after cancellation settles
  }
}

Prevention

When it happens

Trigger: Thread interrupted during open() while blocked in client.blockUntilConnected(...) — typically task cancellation or JVM shutdown during lock factory initialization.

Common situations: Flink cancels the maintenance trigger during startup; kill signals interrupt the connecting thread; job restart racing with slow ZooKeeper connect (cross-DC latency).

Related errors


AI-assisted analysis of apache/iceberg@86d9c8fc54 (2026-09-12). Data as JSON: /api/errors/802eec00b82492f2. Report an issue: GitHub.