{"record":{"id":"b0769fcafac8b517","repo":"prestodb/presto","slug":"error-fetching-results","errorCode":null,"errorMessage":"Error fetching results","messagePattern":"Error fetching results","errorType":"exception","errorClass":"SQLException","httpStatus":null,"severity":"error","filePath":"presto-jdbc/src/main/java/com/facebook/presto/jdbc/PrestoResultSet.java","lineNumber":157,"sourceCode":"\n    @Override\n    public boolean next()\n            throws SQLException\n    {\n        checkOpen();\n        try {\n            if (!results.hasNext()) {\n                row.set(null);\n                return false;\n            }\n            row.set(results.next());\n            return true;\n        }\n        catch (RuntimeException e) {\n            if (e.getCause() instanceof SQLException) {\n                throw (SQLException) e.getCause();\n            }\n            throw new SQLException(\"Error fetching results\", e);\n        }\n    }\n\n    @Override\n    public void close()\n            throws SQLException\n    {\n        closed.set(true);\n        client.close();\n    }\n\n    @Override\n    public boolean wasNull()\n            throws SQLException\n    {\n        return wasNull.get();\n    }\n","sourceCodeStart":139,"sourceCodeEnd":175,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-jdbc/src/main/java/com/facebook/presto/jdbc/PrestoResultSet.java#L139-L175","documentation":"ResultSet.next() advances the row cursor by pulling the next row from the query results stream. Any RuntimeException raised while fetching (transport failure, protocol error, server-side failure surfacing through the client) is wrapped into a SQLException with message \"Error fetching results\" and the original cause attached — unless the cause is already a SQLException, which is rethrown as-is. It means results could not be retrieved from the Presto coordinator, not that the result set was exhausted.","triggerScenarios":"Calling next() when the underlying HTTP connection to the coordinator drops mid-stream, the server returns a query error/failure while streaming pages, or the results client throws an unchecked exception (e.g. deserialization failure of a results page).","commonSituations":"Long-running queries whose pages take longer than coordinator limits; coordinator restarts or load balancer idle timeouts during result streaming; network partitions; query killed server-side mid-iteration while the client loops over rows.","solutions":["Inspect the cause chain (getCause()) for the real transport or server error and address it","Retry the whole query (re-execute the statement) with a fresh ResultSet; result sets are not resumable","Reduce result size (LIMIT, pagination, or server paging) to shorten streaming time","Check coordinator health/load-balancer idle timeouts and increase them if large gaps between pages occur"],"exampleFix":"// before\nwhile (rs.next()) { ... } // whole loop dies on one transient failure\n// after\ntry {\n    while (rs.next()) { ... }\n}\ncatch (SQLException e) {\n    e.getCause().printStackTrace();\n    rs = stmt.executeQuery(sql); // re-run the query and start over\n}","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"boolean done = false;\nfor (int attempt = 0; attempt < 3 && !done; attempt++) {\n    try (ResultSet rs = stmt.executeQuery(sql)) {\n        while (rs.next()) { /* consume rows */ }\n        done = true;\n    }\n    catch (SQLException e) {\n        if (e.getMessage().equals(\"Error fetching results\") && attempt < 2) continue; // re-run whole query\n        throw e;\n    }\n}","preventionTips":["Consume result sets promptly; idle gaps between next() calls can hit idle timeouts","Keep results small with LIMIT/pagination instead of streaming huge result sets","Always log the full cause chain — the wrapped cause names the real transport/server failure","Monitor coordinator health and load-balancer/proxy idle timeouts"],"tags":["jdbc","resultset","network","query-execution"],"backgroundTag":"result-fetch-failed","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"}