{"record":{"id":"57eee9f177b01123","repo":"apache/dolphinscheduler","slug":"failed-to-cancel-job-run","errorCode":null,"errorMessage":"Failed to cancel job run! ","messagePattern":"Failed to cancel job run! ","errorType":"exception","errorClass":"AliyunServerlessSparkTaskException","httpStatus":null,"severity":"error","filePath":"dolphinscheduler-task-plugin/dolphinscheduler-task-aliyunserverlessspark/src/main/java/org/apache/dolphinscheduler/plugin/task/aliyunserverlessspark/AliyunServerlessSparkTask.java","lineNumber":227,"sourceCode":"        }\n    }\n\n    @Override\n    public AbstractParameters getParameters() {\n        return aliyunServerlessSparkParameters;\n    }\n\n    @Override\n    public void cancelApplication() throws TaskException {\n        CancelJobRunRequest cancelJobRunRequest = buildCancelJobRunRequest();\n        RetryUtils.retryFunction(\n                () -> {\n                    try {\n                        return aliyunServerlessSparkClient.cancelJobRun(\n                                aliyunServerlessSparkParameters.getWorkspaceId(), jobRunId,\n                                cancelJobRunRequest);\n                    } catch (Exception e) {\n                        throw new AliyunServerlessSparkTaskException(\"Failed to cancel job run! \", e);\n                    }\n                }, retryPolicy);\n    }\n\n    @Override\n    public List<String> getApplicationIds() throws TaskException {\n        return Collections.emptyList();\n    }\n\n    protected Client buildAliyunServerlessSparkClient(String accessKeyId, String accessKeySecret,\n                                                      String regionId, String endpoint) throws Exception {\n        if (StringUtils.isEmpty(endpoint)) {\n            endpoint = String.format(AliyunServerlessSparkConstants.ENDPOINT_TEMPLATE, regionId);\n        }\n\n        Config config = new Config()\n                .setEndpoint(endpoint)\n                .setAccessKeyId(accessKeyId)","sourceCodeStart":209,"sourceCodeEnd":245,"githubUrl":"https://github.com/apache/dolphinscheduler/blob/02eac45a1b6676e639fcbfb4be2243de5771b05d/dolphinscheduler-task-plugin/dolphinscheduler-task-aliyunserverlessspark/src/main/java/org/apache/dolphinscheduler/plugin/task/aliyunserverlessspark/AliyunServerlessSparkTask.java#L209-L245","documentation":"During cancelApplication, the task wraps any exception from cancelJobRun into AliyunServerlessSparkTaskException with this message. The kill/cancel request against the Aliyun Serverless Spark job run failed and the job may keep running.","triggerScenarios":"aliyunServerlessSparkClient.cancelJobRun(workspaceId, jobRunId, cancelJobRunRequest) throws — job run already in a terminal state, invalid workspaceId/jobRunId, auth failure, or network error while the user kills the task.","commonSituations":"User clicks 'kill' in DolphinScheduler after the job already finished (cancel on terminal state is rejected); credentials lack CancelJobRun permission; the jobRunId was garbage-collected; Aliyun API throttling during cancellation.","solutions":["Check the wrapped cause: 'invalid state' means the job already finished and can be ignored","Verify workspaceId/jobRunId and that the job run is in a cancellable state","Grant the AK/SK CancelJobRun permission","Retry cancel or manually kill the job in the Aliyun console"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// check job run state before cancelling\nGetJobRunResponse resp = client.getJobRun(workspaceId, jobRunId, new GetJobRunRequest());\nString state = resp.getBody().getJobRun().getState();\nboolean cancellable = !(\"COMPLETED\".equals(state) || \"FAILED\".equals(state) || \"CANCELLED\".equals(state));","typeGuard":null,"tryCatchPattern":"try {\n    task.cancelApplication();\n} catch (TaskException e) {\n    log.warn(\"Cancel failed (job may already be terminal): {}\", e.getMessage(), e);\n}","preventionTips":["Check the job run state before cancelling","Grant CancelJobRun permission to the credentials","Expect cancel races with job completion; treat as benign","Manually verify in the Aliyun console after a failed cancel"],"tags":["aliyun","spark","cancel","api-call-failed"],"backgroundTag":"api-request-failed","analyzedSha":"02eac45a1b6676e639fcbfb4be2243de5771b05d","analyzedAt":"2026-09-06T17:43:00.555Z","contentChangedAt":"2026-09-06T17:43:00.555Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}