From c5e5fa4d97100585dc30c7f0cf4760c4bd96849c Mon Sep 17 00:00:00 2001 From: Rob Syme Date: Thu, 2 Jan 2025 15:48:17 -0500 Subject: [PATCH 1/4] Only close the cache db if it is not null. This fixes a bug where the cache db is not closed if an exception occurs when opening it. This unhandled exception will cause Nextflow to fail and prevent the Global.cleanUp() from being called. Signed-off-by: Rob Syme --- modules/nextflow/src/main/groovy/nextflow/Session.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/nextflow/src/main/groovy/nextflow/Session.groovy b/modules/nextflow/src/main/groovy/nextflow/Session.groovy index f394245259..ad29ad3538 100644 --- a/modules/nextflow/src/main/groovy/nextflow/Session.groovy +++ b/modules/nextflow/src/main/groovy/nextflow/Session.groovy @@ -1226,7 +1226,7 @@ class Session implements ISession { log.warn("Failed to cleanup work dir: ${workDir.toUriString()}") } finally { - db.close() + db?.close() } } From 4b487ffe521b8b692ae80c907335639c27ddec9e Mon Sep 17 00:00:00 2001 From: Rob Syme Date: Thu, 2 Jan 2025 17:07:55 -0500 Subject: [PATCH 2/4] Log the exception message if the work directory cleanup fails. Signed-off-by: Rob Syme --- modules/nextflow/src/main/groovy/nextflow/Session.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/nextflow/src/main/groovy/nextflow/Session.groovy b/modules/nextflow/src/main/groovy/nextflow/Session.groovy index ad29ad3538..2a0c51f35a 100644 --- a/modules/nextflow/src/main/groovy/nextflow/Session.groovy +++ b/modules/nextflow/src/main/groovy/nextflow/Session.groovy @@ -1223,7 +1223,7 @@ class Session implements ISession { log.trace "Clean workdir complete" } catch( Exception e ) { - log.warn("Failed to cleanup work dir: ${workDir.toUriString()}") + log.warn("Failed to cleanup work dir: ${workDir.toUriString()}. Exception: ${e.message}") } finally { db?.close() From 7e0b896c8724b1ed420ec44d1c4c54a7faf0274f Mon Sep 17 00:00:00 2001 From: Rob Syme Date: Fri, 3 Jan 2025 08:58:42 -0500 Subject: [PATCH 3/4] Use try-with-resources to close CacheDB. Signed-off-by: Rob Syme --- modules/nextflow/src/main/groovy/nextflow/Session.groovy | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/modules/nextflow/src/main/groovy/nextflow/Session.groovy b/modules/nextflow/src/main/groovy/nextflow/Session.groovy index 2a0c51f35a..9125e615e4 100644 --- a/modules/nextflow/src/main/groovy/nextflow/Session.groovy +++ b/modules/nextflow/src/main/groovy/nextflow/Session.groovy @@ -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 ) { @@ -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) } } From df8b3874b497ade820a4d814001ffbec793aa94c Mon Sep 17 00:00:00 2001 From: Rob Syme Date: Fri, 3 Jan 2025 14:34:43 -0500 Subject: [PATCH 4/4] Move log.trace out of try-with-resources block. Signed-off-by: Rob Syme --- modules/nextflow/src/main/groovy/nextflow/Session.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/nextflow/src/main/groovy/nextflow/Session.groovy b/modules/nextflow/src/main/groovy/nextflow/Session.groovy index 9125e615e4..7405949971 100644 --- a/modules/nextflow/src/main/groovy/nextflow/Session.groovy +++ b/modules/nextflow/src/main/groovy/nextflow/Session.groovy @@ -1209,8 +1209,8 @@ class Session implements ISession { if( aborted || cancelled || error ) return + log.trace "Cleaning-up workdir" try (CacheDB db = CacheFactory.create(uniqueId, runName).openForRead()) { - log.trace "Cleaning-up workdir" db.eachRecord { HashCode hash, TraceRecord record -> def deleted = db.removeTaskEntry(hash) if( deleted ) {