njnu-seafish commented on code in PR #17696:
URL: 
https://github.com/apache/dolphinscheduler/pull/17696#discussion_r2575692277


##########
dolphinscheduler-task-plugin/dolphinscheduler-task-procedure/src/main/java/org/apache/dolphinscheduler/plugin/task/procedure/ProcedureTask.java:
##########
@@ -105,30 +108,49 @@ public void handle(TaskCallBack taskCallBack) throws 
TaskException {
             }
             String proceduerSql = formatSql(sqlParamsMap, paramsMap);
             // call method
-            try (CallableStatement stmt = 
connection.prepareCall(proceduerSql)) {
+            try (CallableStatement tmpStatement = 
connection.prepareCall(proceduerSql)) {
+                sessionStatement = tmpStatement;
                 // set timeout
-                setTimeout(stmt);
+                setTimeout(tmpStatement);
 
                 // outParameterMap
-                Map<Integer, Property> outParameterMap = 
getOutParameterMap(stmt, sqlParamsMap, paramsMap);
+                Map<Integer, Property> outParameterMap = 
getOutParameterMap(tmpStatement, sqlParamsMap, paramsMap);
 
-                stmt.executeUpdate();
+                tmpStatement.executeUpdate();
 
                 // print the output parameters to the log
-                printOutParameter(stmt, outParameterMap);
+                printOutParameter(tmpStatement, outParameterMap);
 
                 setExitStatusCode(EXIT_CODE_SUCCESS);
             }
         } catch (Exception e) {
+            if (exitStatusCode == TaskConstants.EXIT_CODE_KILL) {
+                log.info("procedure task has been killed");
+                return;
+            }
             setExitStatusCode(EXIT_CODE_FAILURE);
             log.error("procedure task error", e);
             throw new TaskException("Execute procedure task failed", e);
         }
     }
 
     @Override
-    public void cancel() throws TaskException {
-
+    public void cancel() {
+        Statement stmt = this.sessionStatement;
+        if (stmt != null) {
+            try {
+                log.debug("Try to cancel this procedure task");
+                stmt.cancel();
+                setExitStatusCode(TaskConstants.EXIT_CODE_KILL);

Review Comment:
   > The exit status code should be set to EXIT_CODE_KILL before attempting to 
cancel the statement. If stmt.cancel() throws an exception, the exit status 
will not be set, which could lead to incorrect task status reporting. Consider 
moving line 144 before line 143.
   
   good



-- 
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