Skip to content

fix: stop flink job error by using flink cancel command before process kill - #18554

Open
shenshichao163-oss wants to merge 1 commit into
apache:devfrom
shenshichao163-oss:fix/flink-stop-job-error
Open

fix: stop flink job error by using flink cancel command before process kill#18554
shenshichao163-oss wants to merge 1 commit into
apache:devfrom
shenshichao163-oss:fix/flink-stop-job-error

Conversation

@shenshichao163-oss

Copy link
Copy Markdown

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

  • I have searched the issues of this repository and believe that this is not a duplicate.
  • I have checked that this modification does not cause CI to fail.
  • I will sign the Apache CLA if required.
  • The code follows the projects coding style.

…s kill

- Override cancelApplication() in FlinkTask to first attempt graceful
  cancellation via 'flink cancel <appId>' command
- Fall back to process-level kill (SIGINT/SIGTERM/SIGKILL) if flink cancel
  fails or appIds are unavailable
- This fixes the issue where stopping Flink tasks from the page would
  fail to send proper kill signals, causing errors in worker node logs

Fixes apache#16789
@boring-cyborg

boring-cyborg Bot commented Aug 15, 2026

Copy link
Copy Markdown

Thanks for opening this pull request! Please check out our contributing guidelines. (https://github.com/apache/dolphinscheduler/blob/dev/docs/docs/en/contribute/join/pull-request.md)

@SbloodyS SbloodyS added first time contributor First-time contributor bug Something isn't working labels Aug 16, 2026

@SbloodyS SbloodyS left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please follow PR template and fill in the form.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend bug Something isn't working first time contributor First-time contributor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] [Flink] stop flink job error

2 participants