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

  1. Check why the thread was interrupted — most often a test timeout. Raise the timeout if cluster startup is legitimately slow.
  2. Ensure the node actually boots in a reasonable time; investigate slow startup from the node logs.
  3. 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

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


AI-assisted analysis of elastic/elasticsearch@db6a809a66 (2026-08-12). Data as JSON: /api/errors/13d72baa52308034. Report an issue: GitHub.