Fix task log appender will not be closed immediate after throwing exception (#14989)

(cherry picked from commit 629fced9ef)
This commit is contained in:
Wenjun Ruan 2023-10-08 09:19:02 +08:00 committed by Jay Chung
parent f2c68bc97a
commit 512f94070a
1 changed files with 3 additions and 2 deletions

View File

@ -56,9 +56,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);
}
@ -70,6 +71,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 {
@ -112,7 +114,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();