{"record":{"id":"db4a8d9d3d94c85d","repo":"prestodb/presto","slug":"error-fetching-next-attempts-s-duration-s","errorCode":null,"errorMessage":"Error fetching next (attempts: %s, duration: %s)","messagePattern":"Error fetching next \\(attempts: (.+?), duration: (.+?)\\)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"presto-client/src/main/java/com/facebook/presto/client/StatementClientV1.java","lineNumber":392,"sourceCode":"            return false;\n        }\n        validateNextUriSource(nextUri, currentStatusInfo().getInfoUri());\n\n        Request request = prepareRequest(HttpUrl.get(nextUri)).build();\n\n        Exception cause = null;\n        long start = System.nanoTime();\n        long attempts = 0;\n\n        while (true) {\n            if (isClientAborted()) {\n                return false;\n            }\n\n            Duration sinceStart = Duration.nanosSince(start);\n            if (attempts > 0 && sinceStart.compareTo(requestTimeoutNanos) > 0) {\n                state.compareAndSet(State.RUNNING, State.CLIENT_ERROR);\n                throw new RuntimeException(format(\"Error fetching next (attempts: %s, duration: %s)\", attempts, sinceStart), cause);\n            }\n\n            if (attempts > 0) {\n                // back-off on retry\n                try {\n                    MILLISECONDS.sleep(attempts * 100);\n                }\n                catch (InterruptedException e) {\n                    try {\n                        close();\n                    }\n                    finally {\n                        Thread.currentThread().interrupt();\n                    }\n                    state.compareAndSet(State.RUNNING, State.CLIENT_ERROR);\n                    throw new RuntimeException(\"StatementClient thread was interrupted\");\n                }\n            }","sourceCodeStart":374,"sourceCodeEnd":410,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-client/src/main/java/com/facebook/presto/client/StatementClientV1.java#L374-L410","documentation":"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.","triggerScenarios":"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.","commonSituations":"Coordinator overloaded or restarted mid-query; network partitions or flaky LBs; requestTimeout (client) set too low for a busy cluster; coordinator OOM-killed.","solutions":["Inspect the chained cause (getCause()) for the underlying I/O/HTTP error.","Increase the client requestTimeout / add retries in the calling application.","Check coordinator health and logs (/coordinator UI, GC logs) at the failure time.","Verify network stability/proxy timeouts between client and coordinator.","Implement backoff-and-reconnect at the application level using the client's error state."],"exampleFix":"// before\nPrestoSession.builder().setRequestTimeout(new Duration(5, SECONDS))...\n// after\nPrestoSession.builder().setRequestTimeout(new Duration(60, SECONDS))...","handlingStrategy":"retry","validationCode":"HttpURLConnection c = (HttpURLConnection) new URL(server + \"/v1/status\").openConnection();\nc.setConnectTimeout(5000);\nif (c.getResponseCode() != 200) throw new IllegalStateException(\"Coordinator not reachable within timeout\");","typeGuard":null,"tryCatchPattern":"try {\n    while (client.isRunning()) client.advance();\n} catch (RuntimeException e) {\n    if (e.getMessage() != null && e.getMessage().startsWith(\"Error fetching next\")) {\n        // inspect e.getCause(), wait, then restart the query with backoff\n    } else throw e;\n}","preventionTips":["Set a requestTimeout generous enough for cluster load","Monitor coordinator health and GC","Handle client error state with application-level retries","Avoid fragile LBs/proxies with short idle timeouts"],"tags":["network","timeout","http","retry"],"backgroundTag":"request-timeout","analyzedSha":"55bb57d202de3b926896fa966c2c4a44c779634e","analyzedAt":"2026-09-04T12:50:26.162Z","contentChangedAt":"2026-09-04T12:50:26.162Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}