From 629fced9efa0724463bcfe9410486d79af482a2a Mon Sep 17 00:00:00 2001 From: Wenjun Ruan Date: Sun, 8 Oct 2023 09:19:02 +0800 Subject: [PATCH] Fix task log appender will not be closed immediate after throwing exception (#14989) --- .../master/runner/execute/MasterTaskExecuteRunnable.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/execute/MasterTaskExecuteRunnable.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/execute/MasterTaskExecuteRunnable.java index 5fa1364616..9e08c1a4d2 100644 --- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/execute/MasterTaskExecuteRunnable.java +++ b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/execute/MasterTaskExecuteRunnable.java @@ -55,9 +55,10 @@ public abstract class MasterTaskExecuteRunnable implements Runnable { protected abstract void afterExecute() throws MasterTaskExecuteException; protected void afterThrowing(Throwable throwable) { + TaskInstanceLogHeader.printFinalizeTaskHeader(); try { + log.error("Get a exception when execute the task, will try to cancel the task", throwable); cancelTask(); - log.error("Get a exception when execute the task, canceled the task", throwable); } catch (Exception e) { log.error("Cancel task failed,", e); } @@ -69,6 +70,7 @@ public abstract class MasterTaskExecuteRunnable implements Runnable { MasterTaskExecutionContextHolder.removeTaskExecutionContext(taskExecutionContext.getTaskInstanceId()); MasterTaskExecuteRunnableHolder.removeMasterTaskExecuteRunnable(taskExecutionContext.getTaskInstanceId()); log.info("Get a exception when execute the task, removed the TaskExecutionContext"); + closeLogAppender(); } public void cancelTask() throws MasterTaskExecuteException { @@ -111,7 +113,6 @@ public abstract class MasterTaskExecuteRunnable implements Runnable { } catch (Throwable ex) { log.error("Task execute failed, due to meet an exception", ex); afterThrowing(ex); - closeLogAppender(); } finally { LogUtils.removeWorkflowAndTaskInstanceIdMDC(); LogUtils.removeTaskInstanceLogFullPathMDC();