{"record":{"id":"7406eb2523d802e2","repo":"apache/iceberg","slug":"failed-to-close-connection","errorCode":null,"errorMessage":"Failed to close connection","messagePattern":"Failed to close connection","errorType":"exception","errorClass":"UncheckedSQLException","httpStatus":null,"severity":"warning","filePath":"core/src/main/java/org/apache/iceberg/jdbc/JdbcClientPool.java","lineNumber":105,"sourceCode":"      Properties dbProps = JdbcUtil.filterAndRemovePrefix(properties, JdbcCatalog.PROPERTY_PREFIX);\n      return DriverManager.getConnection(dbUrl, dbProps);\n    } catch (SQLException e) {\n      throw new UncheckedSQLException(e, \"Failed to connect: %s\", dbUrl);\n    }\n  }\n\n  @Override\n  protected Connection reconnect(Connection client) {\n    close(client);\n    return newClient();\n  }\n\n  @Override\n  protected void close(Connection client) {\n    try {\n      client.close();\n    } catch (SQLException e) {\n      throw new UncheckedSQLException(e, \"Failed to close connection\");\n    }\n  }\n\n  @Override\n  protected boolean isConnectionException(Exception e) {\n    return super.isConnectionException(e)\n        || (e instanceof SQLException\n            && retryableStatusCodes.contains(((SQLException) e).getSQLState()));\n  }\n}\n","sourceCodeStart":87,"sourceCodeEnd":116,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/core/src/main/java/org/apache/iceberg/jdbc/JdbcClientPool.java#L87-L116","documentation":"Thrown when closing a pooled JDBC connection raises a SQLException. JdbcClientPool.close() calls client.close() and converts failures into UncheckedSQLException. This usually signals an already-broken connection or driver-level teardown problem while releasing resources back to the pool.","triggerScenarios":"JdbcClientPool.close(client) fails when Connection.close() throws SQLException — e.g. the connection was already terminated by the server or network dropped mid-close.","commonSituations":"Database restarted or connection killed by idle timeouts while in the pool, network partition during teardown, driver bugs on close after a stale connection.","solutions":["Set connection validation and idle timeout settings so stale connections are evicted before reuse/close.","Check for a keepalive/test-on-borrow configuration supported by JdbcClientPool properties (e.g. keepalive.time).","Verify network stability between client and database.","Upgrade the JDBC driver if close() failures are a known driver issue.","Catch UncheckedSQLException around catalog close in application shutdown code to avoid masking other shutdown errors."],"exampleFix":"// before\nMap<String, String> props = Map.of(\"uri\", url); // no keepalive, stale conns\n// after\nMap<String, String> props = Map.of(\n  \"uri\", url,\n  \"keepalive.time\", \"120000\",\n  \"jdbc.test-on-borrow\", \"true\");","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  catalog.close();\n} catch (UncheckedSQLException e) {\n  org.slf4j.LoggerFactory.getLogger(\"app\").warn(\"Connection close failed; pool may hold stale connections\", e);\n}","preventionTips":["Configure keepalive/test-on-borrow so stale connections are evicted.","Set pool idle timeouts below the DB server's connection idle kill threshold.","Catch close failures in shutdown paths so they don't mask real errors."],"tags":["jdbc","database","resource-cleanup"],"backgroundTag":"database-query-failed","analyzedSha":"86d9c8fc543e7c56c9f624eb725f76c9baff9570","analyzedAt":"2026-09-12T00:46:39.097Z","contentChangedAt":"2026-09-12T00:46:39.097Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}