Skip to content

Commit

Permalink
Use try-with-resources to close CacheDB.
Browse files Browse the repository at this point in the history
  • Loading branch information
robsyme committed Jan 3, 2025
1 parent 4b487ff commit 8003dfb
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions modules/nextflow/src/main/groovy/nextflow/Session.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -1209,10 +1209,8 @@ class Session implements ISession {
if( aborted || cancelled || error )
return

CacheDB db = null
try {
try (CacheDB db = CacheFactory.create(uniqueId, runName).openForRead()) {
log.trace "Cleaning-up workdir"
db = CacheFactory.create(uniqueId, runName).openForRead()
db.eachRecord { HashCode hash, TraceRecord record ->
def deleted = db.removeTaskEntry(hash)
if( deleted ) {
Expand All @@ -1223,10 +1221,7 @@ class Session implements ISession {
log.trace "Clean workdir complete"
}
catch( Exception e ) {
log.warn("Failed to cleanup work dir: ${workDir.toUriString()}. Exception: ${e.message}")
}
finally {
db?.close()
log.warn("Failed to cleanup work dir: ${workDir.toUriString()}", e)
}
}

Expand Down

0 comments on commit 8003dfb

Please sign in to comment.