{"record":{"id":"8134949a463ee957","repo":"prestodb/presto","slug":"connection-is-closed","errorCode":null,"errorMessage":"Connection is closed","messagePattern":"Connection is closed","errorType":"exception","errorClass":"SQLException","httpStatus":null,"severity":"error","filePath":"presto-jdbc/src/main/java/com/facebook/presto/jdbc/PrestoConnection.java","lineNumber":879,"sourceCode":"\n    PrestoResultSet invokeQueryInterceptorsPost(String sql, Statement interceptedStatement, PrestoResultSet originalResultSet)\n    {\n        PrestoResultSet interceptedResultSet = originalResultSet;\n\n        for (QueryInterceptor interceptor : this.queryInterceptorInstances) {\n            Optional<PrestoResultSet> newResultSet = interceptor.postProcess(sql, interceptedStatement, interceptedResultSet);\n            if (newResultSet.isPresent()) {\n                interceptedResultSet = newResultSet.get();\n            }\n        }\n        return interceptedResultSet;\n    }\n\n    private void checkOpen()\n            throws SQLException\n    {\n        if (isClosed()) {\n            throw new SQLException(\"Connection is closed\");\n        }\n    }\n\n    private void initializeQueryInterceptors()\n    {\n        for (QueryInterceptor interceptor : this.queryInterceptorInstances) {\n            interceptor.init(this.sessionProperties);\n        }\n    }\n\n    private static void checkResultSet(int resultSetType, int resultSetConcurrency)\n            throws SQLFeatureNotSupportedException\n    {\n        if (resultSetType != ResultSet.TYPE_FORWARD_ONLY) {\n            throw new SQLFeatureNotSupportedException(\"Result set type must be TYPE_FORWARD_ONLY\");\n        }\n        if (resultSetConcurrency != ResultSet.CONCUR_READ_ONLY) {\n            throw new SQLFeatureNotSupportedException(\"Result set concurrency must be CONCUR_READ_ONLY\");","sourceCodeStart":861,"sourceCodeEnd":897,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-jdbc/src/main/java/com/facebook/presto/jdbc/PrestoConnection.java#L861-L897","documentation":"PrestoConnection.checkOpen() throws this SQLException whenever any connection-level operation (createStatement, prepareStatement, setCatalog, commit, etc.) is invoked after the connection has been closed via close() or aborted. It is a standard JDBC precondition check: the driver has no open HTTP session to the Presto coordinator to send requests on. Once closed, the connection object is permanently unusable; JDBC does not support reopening it.","triggerScenarios":"Calling any method on a PrestoConnection after close() or abort() was called; using a connection returned from a pool that was already closed (double-close/double-checkout bug); keeping a long-lived connection past its idle timeout and reusing it after application-level close; using a connection after its backing session was killed.","commonSituations":"Connection-pool misconfiguration (stale/evicted connections handed out by cached pools like homegrown maps); forgetting to re-obtain a connection per request in long-running apps; closing a connection in a finally block and then using it again in later code; JDBC 4.1 try-with-resources variable referenced outside the try block.","solutions":["Obtain a fresh connection via DriverManager.getConnection(...) before the operation","Use try-with-resources so a connection is never used after close","If pooling, use a real pool (HikariCP) with connection validation instead of manual caching","Check isClosed() before reusing a cached connection"],"exampleFix":"// before\nConnection conn = map.get(\"presto\");\nconn.createStatement().execute(query); // throws if conn was closed earlier\n// after\ntry (Connection conn = DriverManager.getConnection(url, user, password)) {\n    conn.createStatement().execute(query);\n}","handlingStrategy":"try-catch","validationCode":"if (conn == null || conn.isClosed()) {\n    conn = DriverManager.getConnection(url, user, password);\n}","typeGuard":null,"tryCatchPattern":"try {\n    stmt = conn.createStatement();\n} catch (SQLException e) {\n    if (\"Connection is closed\".equals(e.getMessage())) {\n        conn = DriverManager.getConnection(url, user, password);\n        stmt = conn.createStatement();\n    } else {\n        throw e;\n    }\n}","preventionTips":["Use try-with-resources for every connection","Never cache raw Connections; use a connection pool with validity checks","Call isClosed() before reusing a long-lived connection"],"tags":["jdbc","connection-lifecycle","presto"],"backgroundTag":"connection-closed","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"}