guoshupei commented on code in PR #10613:
URL: https://github.com/apache/dolphinscheduler/pull/10613#discussion_r907942893


##########
dolphinscheduler-worker/src/main/java/org/apache/dolphinscheduler/server/worker/runner/TaskExecuteThread.java:
##########
@@ -192,20 +193,23 @@ public void run() {
                 sendAlert(this.task.getTaskAlertInfo(), 
this.task.getExitStatus().getCode());
             }
 
-            
taskExecutionContext.setCurrentExecutionStatus(ExecutionStatus.of(this.task.getExitStatus().getCode()));
-            taskExecutionContext.setEndTime(DateUtils.getCurrentDate());
-            taskExecutionContext.setProcessId(this.task.getProcessId());
-            taskExecutionContext.setAppIds(this.task.getAppIds());
             
taskExecutionContext.setVarPool(JSONUtils.toJsonString(this.task.getParameters().getVarPool()));
-            logger.info("task instance id : {},task final status : {}", 
taskExecutionContext.getTaskInstanceId(), this.task.getExitStatus());
+
+            logger.info("task instance id : {}, task final status : {}", 
taskExecutionContext.getTaskInstanceId(), this.task.getExitStatus());
         } catch (Throwable e) {
-            logger.error("task scheduler failure", e);
+            logger.error("task instance id : {}, scheduler failure", 
taskExecutionContext.getTaskInstanceId(), e);
+            errorFlag = true;
             kill();
-            
taskExecutionContext.setCurrentExecutionStatus(ExecutionStatus.FAILURE);
+        } finally {
+            if (errorFlag) {
+                
taskExecutionContext.setCurrentExecutionStatus(ExecutionStatus.FAILURE);
+            } else {
+                
taskExecutionContext.setCurrentExecutionStatus(ExecutionStatus.of(this.task.getExitStatus().getCode()));
+            }
             taskExecutionContext.setEndTime(DateUtils.getCurrentDate());
             taskExecutionContext.setProcessId(this.task.getProcessId());

Review Comment:
   How do I determine whether a task is null through executionStatus?There may 
be the same value` ExecutionStatus.FAILURE` in try block and catch block and 
task may also be null.  I think if task throw NPE, it need to add NPE check in 
both catch block and finally block . so I think add check in finally is better.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to