Close connection after use

Description

Hi,
after using liquibase with HikariDatasource we found an issues causing connection leak.

I am not 100% sure but I found at least one not closed connection in your code:

SpringLiquibase.java:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 @Override public void afterPropertiesSet() throws LiquibaseException { ConfigurationProperty shouldRunProperty = LiquibaseConfiguration.getInstance() .getProperty(GlobalConfiguration.class, GlobalConfiguration.SHOULD_RUN); if (!shouldRunProperty.getValue(Boolean.class)) { Scope.getCurrentScope().getLog(getClass()).info(LogType.LOG, "Liquibase did not run because " + LiquibaseConfiguration .getInstance().describeValueLookupLogic(shouldRunProperty) + " was set to false"); return; } if (!shouldRun) { Scope.getCurrentScope().getLog(getClass()).info(LogType.LOG, "Liquibase did not run because 'shouldRun' " + "property was set " + "to false on " + getBeanName() + " Liquibase Spring bean."); return; } Connection c = null; Liquibase liquibase = null; try { c = getDataSource().getConnection(); liquibase = createLiquibase(c); generateRollbackFile(liquibase); performUpdate(liquibase); } catch (SQLException e) { throw new DatabaseException(e); } finally { Database database = null; if (liquibase != null) { database = liquibase.getDatabase(); } if (database != null) { database.close(); } } }

Above you close database, but not connection.
Can you make sure you close connections in all places, where you use them? Or is it by design? If yes, then why?

 

Or better approach is to use try-with-resources if java 7 is the minimum version

Environment

.

Status

Assignee

Unassigned

Reporter

Piotr Joński

Labels

None

Affects versions

3.6.3

Priority

Critical
Configure