dolphinscheduler icon indicating copy to clipboard operation
dolphinscheduler copied to clipboard

[Bug] Workflow remains READY_STOP when task kill status check misclassifies child processes

Open zhuxiangyi opened this issue 6 months ago • 7 comments

Search before asking

  • [x] I had searched in the issues and found no similar issues.

What happened

When stopping a running workflow instance from the Web UI, the workflow can remain in READY_STOP and the task instance can remain RUNNING_EXECUTION even though the worker logs report that the process tree was killed successfully.

Image

In the observed Web UI screenshot, the workflow instance row showed the stop status tooltip as "Preparing Stop" after clicking stop, and it stayed in that state.

The database state was:

select id, name, state, host, start_time, end_time, update_time, state_history
from t_ds_workflow_instance
where id = 94;
id: 94
name: test111-20260601075309950
state: 4
host: 10.57.0.80:5678
start_time: 2026-06-01 07:53:10
end_time: NULL
update_time: 2026-06-01 15:54:12
state_history: SUBMITTED_SUCCESS -> RUNNING_EXECUTION

The running task instance was:

select id, name, state, host, start_time, end_time, log_path
from t_ds_task_instance
where workflow_instance_id = 94
order by id;
id: 136
name: Test
state: 1
host: 10.57.0.209:1234
start_time: 2026-06-01 07:53:10
end_time: NULL
log_path: /data/soft/apache-dolphinscheduler-3.4.1-bin/worker-server/logs/20260601/174970851976672/1/94/136.log

In the affected case, the worker process tree was similar to:

sudo -u airflow -i /tmp/dolphinscheduler/exec/process/136/136.sh
  bash --login -c /tmp/dolphinscheduler/exec/process/136/136.sh
    /bin/bash /tmp/dolphinscheduler/exec/process/136/136.sh
      python3 success_file_check.py ...

More specifically, ps still showed the processes alive after the stop operation:

PID    PPID  PGID   SID   STAT  ELAPSED  CMD
30448   424   372 30429   S     33:21    sudo -u airflow -i /tmp/dolphinscheduler/exec/process/136/136.sh
30451 30448   372 30429   S     33:21    -bash --login -c /tmp/dolphinscheduler/exec/process/136/136.sh
30481 30451   372 30429   S     33:21    /bin/bash /tmp/dolphinscheduler/exec/process/136/136.sh
30514 30481   372 30429   S     33:21    python3 /home/airflow/codes/common/utils/success_file_check.py ...

The master published the stop event and task kill event:

WorkflowStopLifecycleEvent{workflow=test111-20260601075309950}
Success set WorkflowExecuteRunnable state from RUNNING_EXECUTION to READY_STOP
Publish event: TaskKillLifecycleEvent{task=Test, delayTime=0}
Kill task Test on executor 10.57.0.209:1234 successfully

The worker logged:

Begin killing task instance, processId: 30448
prepare to parse pid, raw pid string: sudo(30448)---bash(30451)---136.sh(30481)---python3(30514)
All processes already terminated.
Successfully killed process tree by SIGINT, processId: 30448
Process tree for task: 136 is killed or already finished, pid: 30448

But ps still showed the task process tree alive afterwards.

The tenant process check also showed that the root-owned sudo process existed but was not signalable by the tenant user:

sudo -u airflow -i kill -0 30448; echo $?
/etc/profile.d/history.sh: line 1: HISTSIZE: readonly variable
/etc/profile.d/history.sh: line 2: HISTTIMEFORMAT: readonly variable
-bash: line 0: kill: (30448) - Operation not permitted
1

What you expected to happen

The worker should not report kill success while killable child processes are still alive. It should continue to send the kill signal to child processes that the tenant user can operate on, even if the root-owned sudo parent returns Operation not permitted for kill -0.

How to reproduce

  1. Run a shell task as a tenant through sudo -u <tenant> -i.
  2. Let the shell script start a long-running child process, for example a Python script that sleeps or polls in a loop.
  3. Configure the tenant login shell/profile so sudo -u <tenant> -i kill -0 <pid> can emit stderr even with exit code 0, for example readonly variable warnings from /etc/profile.d.
  4. Stop the workflow instance from the Web UI.
  5. Observe that the worker can mark the process tree as already terminated while child processes remain alive, and the workflow instance can stay in READY_STOP / "Preparing Stop".

Anything else

Root cause:

  • ProcessUtils.isProcessAlive treats every exception from OSUtils.exeCmd("kill -0 <pid>") as "not alive".
  • AbstractShell throws ExitCodeException when stderr is non-empty, even if the command exit code is 0.
  • kill -0 returning Operation not permitted means the process exists but cannot be signalled by the current user, not that the process has exited.

The fix should distinguish alive, not-alive, and no-permission states when checking PIDs before sending kill signals.

Version

3.4.1 and current dev

Are you willing to submit PR?

  • [x] Yes I am willing to submit a PR!

zhuxiangyi avatar Jun 01 '26 23:06 zhuxiangyi

Yes, the current logic for killing shell processes is very unreliable. Do you have any good ideas?

ruanwenjun avatar Jun 03 '26 15:06 ruanwenjun

I have thinked about the design, @ruanwenjun @SbloodyS , could you please take a look and give some suggestions?

Task Process Boundary Design

Design

  • Introduce TaskProcessBoundary for local physical tasks.
  • Create the boundary before launching the task process.
  • Store boundary metadata in task runtime metadata.
  • Kill the boundary directly during task cancellation.
  • Report kill success only after the boundary is verified as terminated.

Boundary Types

  1. SystemdScopeTaskProcessBoundary

    • Preferred on Linux hosts with systemd.
    • Start task with a dedicated transient scope:
      systemd-run --scope --unit dolphinscheduler-task-<taskInstanceId> --uid <tenant> <task-script>
      
    • Kill the whole scope:
      systemctl kill --kill-who=all --signal=SIGTERM <scope>
      systemctl kill --kill-who=all --signal=SIGKILL <scope>
      
  2. ProcessGroupTaskProcessBoundary

    • Fallback when systemd is unavailable.
    • Start task in a new session/process group:
      setsid <task-launch-command>
      
    • Kill the whole process group:
      kill -TERM -<pgid>
      kill -KILL -<pgid>
      
  3. LegacyPidTreeTaskProcessBoundary

    • Compatibility fallback only.
    • Keep current pstree based behavior when no stable boundary is available.

Runtime Metadata

Store supported fields only:

  • boundaryType
  • workerHost
  • tenantCode
  • rootPid
  • processStartTime
  • processGroupId
  • sessionId
  • systemdScopeName
  • cgroupPath

Kill Semantics

  • success=true: the boundary is terminated or already gone.
  • success=false: the boundary cannot be terminated or cannot be verified.
  • Do not report kill success only because the kill request was accepted.
  • Do not add new user-visible kill states in this design.

qiuyanjun888 avatar Jun 18 '26 08:06 qiuyanjun888

When task instance concurrency is high, frequently creating and destroying task-instance-level systemd units can cause system load to spike sharply.

And calling setsid in the program requires forking a process, which introduces new orphan-process issues and further amplifies the current problem.

Neither of these methods is not a good approach, and we should not do it.

SbloodyS avatar Jun 18 '26 08:06 SbloodyS

I looked into this and it seems that using setsid is a relatively straightforward way to prevent orphaned child processes. So far, I haven't found any documentation or evidence suggesting notable performance or resource overhead.

ruanwenjun avatar Jun 19 '26 01:06 ruanwenjun

Hi @ruanwenjun @SbloodyS, thanks for your feedback on my previous design proposal: https://github.com/apache/dolphinscheduler/issues/18311#issuecomment-4739634666.

I have implemented the code based on that design direction and opened PR #18367: https://github.com/apache/dolphinscheduler/pull/18367.

The PR uses a local shell task process-group approach, with configuration support, to make task cancellation kill the whole shell task process group more reliably. It also includes tests and related documentation/configuration updates.

Could you please take a look when you have time and advise whether this direction is acceptable, especially regarding the process-group/setsid concern discussed above? Thanks.

qiuyanjun888 avatar Jun 22 '26 05:06 qiuyanjun888

Regarding the proposed redesign and the implementation in PR #18367, I have a few thoughts following the recent discussion.

While using setsid to manage process groups is a straightforward way to prevent orphaned processes, we should address the concerns raised about potential orphan-process issues introduced by the extra fork and the system load spikes observed when frequently creating systemd units at high concurrency.

Since PR #18312 already addresses the immediate bug involving misclassified liveness detection and the READY_STOP hang, I suggest we evaluate that fix first. For the broader goal of a robust task process boundary, we might want to further explore the native helper approach—similar to Airflow—to achieve setpgid(0, 0) without the downsides of an extra fork.

On Mon, Jun 22, 2026, 12:13 AM Yanjun Qiu @.***> wrote:

qiuyanjun888 left a comment (apache/dolphinscheduler#18311) https://github.com/apache/dolphinscheduler/issues/18311#issuecomment-4765121462

Hi @ruanwenjun https://github.com/ruanwenjun @SbloodyS https://github.com/SbloodyS, thanks for your feedback on my previous design proposal: #18311 (comment) https://github.com/apache/dolphinscheduler/issues/18311#issuecomment-4739634666 .

I have implemented the code based on that design direction and opened PR #18367 https://github.com/apache/dolphinscheduler/pull/18367: #18367 https://github.com/apache/dolphinscheduler/pull/18367.

The PR uses a local shell task process-group approach, with configuration support, to make task cancellation kill the whole shell task process group more reliably. It also includes tests and related documentation/configuration updates.

Could you please take a look when you have time and advise whether this direction is acceptable, especially regarding the process-group/setsid concern discussed above? Thanks.

— Reply to this email directly, view it on GitHub https://github.com/apache/dolphinscheduler/issues/18311?email_source=notifications&email_token=B7GHLXE5A6TN2IWP4MM5FBD5BC6BNA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTINZWGUYTEMJUGYZKM4TFMFZW63VKON2WE43DOJUWEZLEUVSXMZLOOSWGM33PORSXEX3DNRUWG2Y#issuecomment-4765121462, or unsubscribe https://github.com/notifications/unsubscribe-auth/B7GHLXHWBROPKXRTQJJ72CT5BC6BNAVCNFSNUABFKJSXA33TNF2G64TZHMYTOMZTGM2TOMBWHNEXG43VMU5TINJWG4YTMNRWG43KC5QC . Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS https://github.com/notifications/mobile/ios/B7GHLXB5LLBVMGHRYYFJ2BD5BC6BNA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTINZWGUYTEMJUGYZKM4TFMFZW63VKON2WE43DOJUWEZLEUVSXMZLOOSVGM33PORSXEX3JN5ZQ and Android https://github.com/notifications/mobile/android/B7GHLXDACMNYDLX2L4YWLLT5BC6BNA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTINZWGUYTEMJUGYZKM4TFMFZW63VKON2WE43DOJUWEZLEUVSXMZLOOSXGM33PORSXEX3BNZSHE33JMQ. Download it today! You are receiving this because you are subscribed to this thread.Message ID: @.***>

matthewwalker1621-star avatar Jun 22 '26 09:06 matthewwalker1621-star

Since this case will only appear when the user has no authority, it is a small probability event and can be easily avoided before deployment. So we don't need a compromise.

SbloodyS avatar Jun 22 '26 10:06 SbloodyS