Shubhra742 opened a new issue, #18357:
URL: https://github.com/apache/dolphinscheduler/issues/18357

   ### Search before asking
   
   - [x] I had searched in the 
[issues](https://github.com/apache/dolphinscheduler/issues?q=is%3Aissue) and 
found no similar issues.
   
   
   ### What happened
   
   When a worker runs on Windows, two methods in dolphinscheduler-task-api fail 
because they
   rely on Linux-only internals:
   
   AbstractCommandExecutor.getProcessId(Process) reads a private field named 
pid via
   reflection. On Windows the process class (java.lang.ProcessImpl) has no pid 
field — it
   exposes a handle instead — so it throws java.lang.NoSuchFieldException: pid 
and the PID
   defaults to 0.
   Because the PID is 0, ProcessUtils.kill() cannot terminate a running task. 
After the PID
   issue is worked around, kill() still fails on Windows because it relies on 
the Linux
   pstree command and kill -s SIGINT/SIGTERM/SIGKILL signals, which do not 
exist on Windows
   (java.io.IOException: Cannot run program "pstree").
   
   ### What you expected to happen
   
   getProcessId() should return the real OS process id on Windows, and kill() 
should be able to
   terminate the task (and its child process tree) on Windows — without 
changing existing Linux
   behaviour.
   
   ### How to reproduce
   
   Run a worker on Windows (Java 8), registered to a Linux master.
   From the UI run any SHELL task on the Windows worker.
   Observe in the task log:
   ERROR - Get task pid failed  java.lang.NoSuchFieldException: pid
   INFO  - process start, process id is: 0
   Run a long task (e.g. sleep) and click Stop. Observe it cannot be killed; 
after working
   around the PID, the kill fails with Cannot run program "pstree".
   
   ### Anything else
   
   Proposed fix (non-invasive, Linux path unchanged)
   
   Both changes are additive 
   if (OSUtils.isWindows()) { ... } else { <existing Linux code> }, so
   Linux behaviour is byte-for-byte unchanged.
   
   getProcessId(): on Windows read the handle field and convert it to a PID 
using JNA
   Kernel32.INSTANCE.GetProcessId(HANDLE). JNA (jna + jna-platform) is already 
present on
   the worker runtime classpath; it is added to the task-api module with 
provided scope so it
   compiles without being re-bundled.
   ProcessUtils.kill(): on Windows terminate the process tree with the native
   taskkill /F /T /PID <pid> command instead of pstree + kill -s.
   
   Verified on 3.3.2 (Windows Server 2022 worker + Ubuntu master, Java 8):
   - Before: "process start, process id is: 0" + NoSuchFieldException: pid
   - After:  "process start, process id is: 2208" (real PID), task can be 
stopped from UI
   - taskkill /F /T terminates the process tree (verified no orphan processes)
   - Exit codes verified across 12 .sh/.bat scenarios (0 -> SUCCESS; non-zero 
-> FAILED)
   
   ### Version
   
   3.3.2
   
   ### Are you willing to submit PR?
   
   - [x] Yes I am willing to submit a PR!
   
   ### Code of Conduct
   
   - [x] I agree to follow this project's [Code of 
Conduct](https://www.apache.org/foundation/policies/conduct)
   


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