{"record":{"id":"a5524d520966330b","repo":"prestodb/presto","slug":"resultset-thread-was-interrupted","errorCode":null,"errorMessage":"ResultSet thread was interrupted","messagePattern":"ResultSet thread was interrupted","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"presto-jdbc/src/main/java/com/facebook/presto/jdbc/PrestoResultSet.java","lineNumber":1831,"sourceCode":"                }\n            }\n\n            verify(client.isFinished());\n            QueryStatusInfo results = client.finalStatusInfo();\n            progressCallback.accept(QueryStats.create(results.getId(), results.getStats()));\n            warningsManager.addWarnings(results.getWarnings());\n            if (results.getError() != null) {\n                throw new RuntimeException(resultsException(results));\n            }\n\n            return endOfData();\n        }\n\n        private void checkInterruption(Throwable t)\n        {\n            if (Thread.currentThread().isInterrupted()) {\n                client.close();\n                throw new RuntimeException(new SQLException(\"ResultSet thread was interrupted\", t));\n            }\n        }\n    }\n\n    static SQLException resultsException(QueryStatusInfo results)\n    {\n        QueryError error = requireNonNull(results.getError());\n        String message = format(\"Query failed (#%s): %s\", results.getId(), error.getMessage());\n        Throwable cause = (error.getFailureInfo() == null) ? null : error.getFailureInfo().toException();\n        return new SQLException(message, error.getSqlState(), error.getErrorCode(), cause);\n    }\n\n    private static Map<String, Integer> getFieldMap(List<Column> columns)\n    {\n        Map<String, Integer> map = new HashMap<>();\n        for (int i = 0; i < columns.size(); i++) {\n            String name = columns.get(i).getName().toLowerCase(ENGLISH);\n            if (!map.containsKey(name)) {","sourceCodeStart":1813,"sourceCodeEnd":1849,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-jdbc/src/main/java/com/facebook/presto/jdbc/PrestoResultSet.java#L1813-L1849","documentation":"Wrapped SQLException raised inside the ResultSet's async iteration driver thread when Thread.currentThread().isInterrupted() is true. The client connection is closed first, then a RuntimeException carrying the SQLException (with the original cause t) is thrown. It indicates the thread fetching results was interrupted, typically at shutdown or by executor cancellation.","triggerScenarios":"The thread executing ResultSet iteration (checkInterruption path) is interrupted via Thread.interrupt(), e.g. during application shutdown, executor shutdownNow, query cancellation, or a timeout that interrupts the worker.","commonSituations":"Cancelling long-running queries via Future.cancel(true); ExecutorService.shutdownNow() while JDBC fetch threads are blocked; Tomcat/request timeouts interrupting worker threads; poor shutdown ordering where the pool closes before statements do.","solutions":["Close ResultSet/Statement/Connection before interrupting or shutting down the executor","Use query cancellation (Statement.cancel()) instead of Thread.interrupt() to stop a running query","Avoid interrupting threads that own JDBC fetches; run queries with proper lifecycle management","Restore the interrupt status or handle shutdown gracefully in the calling code","Inspect the cause (t) to find who issued the interrupt"],"exampleFix":"// before\nexecutor.shutdownNow(); // interrupts in-flight JDBC fetch\n// after\nstmt.cancel();          // cancel the Presto query first\nrs.close(); stmt.close();\nexecutor.shutdown();","handlingStrategy":"try-catch","validationCode":"// Ensure the owning executor is not shut down before iterating\nif (executor.isShutdown()) throw new IllegalStateException(\"Executor shut down; do not start ResultSet iteration\");","typeGuard":null,"tryCatchPattern":"try (ResultSet rs = stmt.executeQuery(sql)) {\n    while (rs.next()) { /* ... */ }\n} catch (RuntimeException | SQLException e) {\n    Throwable cause = e.getCause();\n    if (cause instanceof SQLException && cause.getMessage() != null && cause.getMessage().contains(\"ResultSet thread was interrupted\")) {\n        Thread.currentThread().interrupt(); // preserve interrupt status\n        return; // graceful shutdown path\n    }\n    throw e;\n}","preventionTips":["Close JDBC resources before interrupting worker threads or shutdownNow()","Use Statement.cancel() rather than Thread.interrupt() to stop Presto queries","Order shutdown: close results/statements first, then executors","Preserve and inspect the interrupt cause to find the interrupting component"],"tags":["jdbc","thread-interrupted","concurrency"],"backgroundTag":"thread-interrupted","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"}