prestodb/presto · error · RuntimeException

Error fetching next (attempts: %s, duration: %s)

Error message

Error fetching next (attempts: %s, duration: %s)

What it means

In StatementClientV1.advance, when request attempts exceed the request timeout, the client transitions to CLIENT_ERROR and throws RuntimeException 'Error fetching next (attempts: N, duration: D)' with the accumulated cause (the last I/O error). It means the coordinator repeatedly failed or was too slow to respond to the next-results request within the configured requestTimeout.

Source

Thrown at presto-client/src/main/java/com/facebook/presto/client/StatementClientV1.java:392

            return false;
        }
        validateNextUriSource(nextUri, currentStatusInfo().getInfoUri());

        Request request = prepareRequest(HttpUrl.get(nextUri)).build();

        Exception cause = null;
        long start = System.nanoTime();
        long attempts = 0;

        while (true) {
            if (isClientAborted()) {
                return false;
            }

            Duration sinceStart = Duration.nanosSince(start);
            if (attempts > 0 && sinceStart.compareTo(requestTimeoutNanos) > 0) {
                state.compareAndSet(State.RUNNING, State.CLIENT_ERROR);
                throw new RuntimeException(format("Error fetching next (attempts: %s, duration: %s)", attempts, sinceStart), cause);
            }

            if (attempts > 0) {
                // back-off on retry
                try {
                    MILLISECONDS.sleep(attempts * 100);
                }
                catch (InterruptedException e) {
                    try {
                        close();
                    }
                    finally {
                        Thread.currentThread().interrupt();
                    }
                    state.compareAndSet(State.RUNNING, State.CLIENT_ERROR);
                    throw new RuntimeException("StatementClient thread was interrupted");
                }
            }

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Inspect the chained cause (getCause()) for the underlying I/O/HTTP error.
  2. Increase the client requestTimeout / add retries in the calling application.
  3. Check coordinator health and logs (/coordinator UI, GC logs) at the failure time.
  4. Verify network stability/proxy timeouts between client and coordinator.
  5. Implement backoff-and-reconnect at the application level using the client's error state.

Example fix

// before
PrestoSession.builder().setRequestTimeout(new Duration(5, SECONDS))...
// after
PrestoSession.builder().setRequestTimeout(new Duration(60, SECONDS))...
Defensive patterns

Strategy: retry

Validate before calling

HttpURLConnection c = (HttpURLConnection) new URL(server + "/v1/status").openConnection();
c.setConnectTimeout(5000);
if (c.getResponseCode() != 200) throw new IllegalStateException("Coordinator not reachable within timeout");

Try / catch

try {
    while (client.isRunning()) client.advance();
} catch (RuntimeException e) {
    if (e.getMessage() != null && e.getMessage().startsWith("Error fetching next")) {
        // inspect e.getCause(), wait, then restart the query with backoff
    } else throw e;
}

Prevention

When it happens

Trigger: Calling advance()/client.next() while the query is running and HTTP requests to /v1/statement keep failing (connection refused, timeouts, 5xx) until total duration since start exceeds requestTimeoutNanos.

Common situations: Coordinator overloaded or restarted mid-query; network partitions or flaky LBs; requestTimeout (client) set too low for a busy cluster; coordinator OOM-killed.

Understand the failure class

Background: Request timed out: what client-side request timeouts mean across libraries (Request timed out, TIMED_OUT, APITimeoutError) — this error's family across 39 libraries.

Related errors


AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04). Data as JSON: /api/errors/db4a8d9d3d94c85d. Report an issue: GitHub.