elastic/elasticsearch · error · TestClustersException
Interrupted while waiting for {}
Error message
Interrupted while waiting for {} What it means
TestClustersException thrown from the cluster-health wait when the polling thread is interrupted (InterruptedException during WaitForHttpResource.wait). The handler re-sets the interrupt flag (Thread.currentThread().interrupt()) before throwing, preserving interrupt status.
Source
Thrown at build-tools/src/main/java/org/elasticsearch/gradle/testclusters/ElasticsearchCluster.java:665
WaitForHttpResource wait = new WaitForHttpResource(
httpSslEnabled ? "https" : "http",
getFirstNode().getHttpSocketURI(),
nodes.size()
);
if (httpSslEnabled) {
getFirstNode().configureHttpWait(wait);
}
List<Map<String, String>> credentials = getFirstNode().getCredentials();
if (getFirstNode().getCredentials().isEmpty() == false) {
wait.setUsername(credentials.get(0).get("useradd"));
wait.setPassword(credentials.get(0).get("-p"));
}
return wait.wait(500);
} catch (IOException e) {
throw new UncheckedIOException("IO error while waiting cluster", e);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new TestClustersException("Interrupted while waiting for " + this, e);
} catch (GeneralSecurityException e) {
throw new RuntimeException("security exception", e);
}
});
}
@Nested
public NamedDomainObjectContainer<ElasticsearchNode> getNodes() {
return nodes;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ElasticsearchCluster that = (ElasticsearchCluster) o;
return Objects.equals(clusterName, that.clusterName) && Objects.equals(path, that.path);
}View on GitHub (pinned to db6a809a66)
Solutions
- Check why the thread was interrupted — most often a test timeout. Raise the timeout if cluster startup is legitimately slow.
- Ensure the node actually boots in a reasonable time; investigate slow startup from the node logs.
- If intentional cancellation, propagate/catch InterruptedException cleanly rather than letting it surface as TestClustersException.
Defensive patterns
Strategy: try-catch
Validate before calling
// Ensure adequate timeout before the wait runs // ./gradlew integTest --timeout 600 // and confirm node startup is not pathologically slow via dry-run timing.
Try / catch
try {
cluster.start();
} catch (TestClustersException e) {
if (Thread.currentThread().isInterrupted()) {
// interrupt-driven; surface or handle cancellation
Thread.currentThread().interrupt();
throw e;
}
throw e;
} Prevention
- Set test timeouts generously enough for cluster startup.
- Investigate chronically slow startup via node logs.
- Avoid cancelling tests mid-startup when feasible.
When it happens
Trigger: Another thread interrupts the test thread while it is blocked in the wait condition — Gradle times out the test, a test framework cancels the task, or user-initiated cancellation.
Common situations: Test task timeout (--timeout or maxWorkerTimeout) fires during cluster startup; CI cancellation; a watchdog thread interrupts long-running waits.
Related errors
- IO error while waiting cluster
- security exception
- Number of nodes should be >= 1 but was {} for {}
- Cannot shrink {} to have {} nodes as it already has {}
- Cannot add nodes to test cluster after is has been frozen
AI-assisted analysis of elastic/elasticsearch@db6a809a66 (2026-08-12).
Data as JSON: /api/errors/13d72baa52308034.
Report an issue: GitHub.