Skip to content

Commit

Permalink
Fix connection leak
Browse files Browse the repository at this point in the history
  • Loading branch information
dmgaldi committed Jul 25, 2024
1 parent 23abd47 commit 3757ae5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

// Project settings
group = "org.veupathdb.eda"
version = "4.16.7"
version = "4.16.8"

plugins {
`java-library`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,11 @@ private static CloseableIterator<Map<String, String>> fileTabularSubsetIterator(
* Oracle-based implementation of tabular record iterator.
*/
private static CloseableIterator<Map<String, String>> oracleTabularSubsetIterator(DataSource dataSource, String appDbSchema, Study study, Entity outputEntity,
List<VariableWithValues> outputVariables, List<Filter> filters) {
List<VariableWithValues> outputVariables, List<Filter> filters) {
TreeNode<Entity> prunedEntityTree = pruneTree(study.getEntityTree(), filters, outputEntity);

String sql = generateTabularSqlForTallRows(appDbSchema, outputVariables, outputEntity, filters, prunedEntityTree);
LOG.debug("Generated the following tabular SQL: " + sql);
LOG.debug("Generated the following tabular SQL: {} with schema {}.", sql, appDbSchema);

// gather the output columns; these will be used for the standard header and to look up DB column values
List<String> outputColumns = getTabularOutputColumns(outputEntity, outputVariables);
Expand All @@ -204,6 +204,10 @@ private static CloseableIterator<Map<String, String>> oracleTabularSubsetIterato
}
catch (Exception e) {
LOG.warn("Exception, ", e);

// Close the connection if we throw an exception initializing the stream.
// It's not in a try-with-resources, because in the happy-path, the upstream caller is responsible for closing resources.
connection.close();
throw new RuntimeException("Unable to write result", e);
}
}, FETCH_SIZE_FOR_TABULAR_QUERIES);
Expand Down Expand Up @@ -239,7 +243,6 @@ public static void produceTabularSubset(DataSource dataSource, String appDbSchem
// write header row
resultConsumer.consumeRow(usePrettyHeader ? getTabularPrettyHeaders(outputEntity, outputVariables) : outputColumns);

LOG.info("Running SQL");
if (reportConfig.requiresSorting())
writeWideRowsFromWideResult(rs, resultConsumer, outputColumns, outputEntity, trimTimeFromDateVars);
else
Expand Down

0 comments on commit 3757ae5

Please sign in to comment.