diff --git a/modules/nextflow/src/main/groovy/nextflow/processor/TaskPollingMonitor.groovy b/modules/nextflow/src/main/groovy/nextflow/processor/TaskPollingMonitor.groovy index a69042f659..29a820624e 100644 --- a/modules/nextflow/src/main/groovy/nextflow/processor/TaskPollingMonitor.groovy +++ b/modules/nextflow/src/main/groovy/nextflow/processor/TaskPollingMonitor.groovy @@ -663,7 +663,7 @@ class TaskPollingMonitor implements TaskMonitor { // finalize the task asynchronously if( enableAsyncFinalizer ) { - finalizerPool.submit( ()-> finalizeTask(handler) ) + finalizerPool.submit( ()-> safeFinalizeTask(handler) ) } else { finalizeTask(handler) @@ -671,6 +671,16 @@ class TaskPollingMonitor implements TaskMonitor { } } + protected void safeFinalizeTask(TaskHandler handler) { + try { + finalizeTask(handler) + } + catch (Throwable t) { + log.error "Unexpected error while finalizing task '${handler.task.name}' - cause: ${t.message}" + session.abort(t) + } + } + protected void finalizeTask( TaskHandler handler ) { // finalize the task execution final fault = handler.task.processor.finalizeTask(handler.task)