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
- 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.
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
- 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
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
- Interrupted during unlock
- Connection to Zookeeper timed out
- Failed to initialize SharedCount
- Failed to check Zookeeper lock status
- Failed to release lock
AI-assisted analysis of apache/iceberg@86d9c8fc54 (2026-09-12).
Data as JSON: /api/errors/802eec00b82492f2.
Report an issue: GitHub.