shenshichao163-oss opened a new pull request, #18554:
URL: https://github.com/apache/dolphinscheduler/pull/18554

   ## What this PR does
   
   Fixes the issue where stopping Flink tasks from the DolphinScheduler page 
fails to send proper kill signals, causing errors in worker node logs.
   
   ### Root Cause
   
   When a user clicks "Stop" on a Flink task, DolphinScheduler uses the generic 
`AbstractCommandExecutor.cancelApplication()` method, which sends OS-level kill 
signals (SIGINT → SIGTERM → SIGKILL) to the process tree. This approach does 
not properly stop the Flink job — it kills the shell process but fails to 
gracefully cancel the Flink application, leading to:
   - Error logs in worker nodes
   - Flink jobs not being properly terminated
   - Resource leaks in the YARN/Kubernetes cluster
   
   ### Fix
   
   Override `cancelApplication()` in `FlinkTask` to:
   
   1. **First attempt graceful cancellation** using the `flink cancel <appId>` 
command (via `FlinkArgsUtils.buildCancelCommandLine()`). This method already 
existed in the codebase but was never called.
   2. **Fall back to process-level kill** (the parent class implementation) if 
the Flink cancel command fails, times out (30s), or no appIds are available.
   
   ### Changes
   
   - **`FlinkTask.java`**: Added `cancelApplication()` override that tries 
`flink cancel` first, then falls back to `super.cancelApplication()`
   - Added imports: `TaskException`, `TaskCallBack`
   
   ### Issue Link
   
   Fixes #16789
   
   ### Before
   
   Stopping a Flink task from the page → 
`AbstractCommandExecutor.cancelApplication()` → `ProcessUtils.kill()` 
(SIGINT/SIGTERM/SIGKILL) → Flink job not properly cancelled, worker logs show 
errors
   
   ### After
   
   Stopping a Flink task from the page → `FlinkTask.cancelApplication()` → 
`flink cancel <appId>` (graceful) → if fails → `super.cancelApplication()` 
(process kill as fallback)
   
   ### Checklist
   
   - [x] I have searched the 
[issues](https://github.com/apache/dolphinscheduler/issues) of this repository 
and believe that this is not a duplicate.
   - [x] I have checked that this modification does not cause CI to fail.
   - [x] I will sign the Apache CLA if required.
   - [x] The code follows the projects coding style.


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