Skip to content

[RUN-3009] implements kill on abort#117

Merged
ronaveva merged 2 commits into
masterfrom
RUN-3009
Jun 16, 2026
Merged

[RUN-3009] implements kill on abort#117
ronaveva merged 2 commits into
masterfrom
RUN-3009

Conversation

@ronaveva

@ronaveva ronaveva commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

This pull request introduces robust process tree termination for WinRM-executed jobs on Windows nodes, addressing the long-standing issue where aborting a job left remote processes running. The main feature is an optional "Terminate On Abort" mode, which—when enabled—ensures that aborting a job kills both the remote command and all its child processes. This is achieved by capturing the remote process PID and force-killing the process tree on abort. The implementation includes new code for PID capture, output filtering, and remote termination, as well as user-facing documentation and configuration options.

The most important changes are:

Process Tree Termination Feature:

  • Added a "Terminate On Abort" option to the plugin configuration (plugin.yaml, README.md). When enabled, aborting a job will terminate the remote command and its entire process tree on the Windows node. This is disabled by default for backward compatibility. [1] [2] [3]

Implementation of Remote PID Capture and Termination:

  • Introduced a new module winrm_kill.py that provides:
    • A preamble to print the remote shell's PID,
    • Functions to parse and strip PID marker lines from output,
    • A MarkerFilter class for streaming output filtering,
    • Logic to send both the WS-Man terminate signal and a taskkill command to kill the entire process tree on abort.

Integration with Job Execution Flow:

  • Modified winrm-exec.py to:
    • Detect the "Terminate On Abort" setting and wrap commands with the PID-capturing preamble,
    • Install signal handlers to catch aborts and trigger remote termination,
    • Filter output to hide PID marker lines and capture the PID,
    • Ensure clean-up and forced exit on abort. [1] [2] [3] [4] [5]

WinRM Session Enhancements:

  • Updated winrm_session.py to:
    • Track live WinRM handles and the remote PID for each running command,
    • Allow abort handlers to access these handles and perform remote termination,
    • Pass a tracker object through command execution to enable this coordination. [1] [2] [3] [4]

Documentation:

  • Expanded the README.md with a new "Aborting jobs" section, explaining the new behavior, configuration, and technical details for users and operators.

These changes collectively ensure that aborting a WinRM-executed job on Windows nodes can now reliably clean up all spawned processes, improving reliability and resource management.

@ronaveva ronaveva added this to the 6.1.0 milestone Jun 3, 2026
Copilot AI review requested due to automatic review settings June 3, 2026 15:57

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR adds an optional “Terminate On Abort” mode to the WinRM node executor so that aborting a Rundeck job can terminate the remote WinRM command and its entire child process tree (via PID capture + taskkill /F /T), addressing orphaned processes on Windows nodes.

Changes:

  • Added remote PID capture + streaming output marker filtering and an abort-time termination routine (terminate_remote) that combines WS-Man terminate + taskkill /T.
  • Wired abort handling into the WinRM execution flow (signal handling, PID propagation via a tracker object).
  • Added user-facing configuration and documentation plus unit tests for the kill helpers.

Reviewed changes

Copilot reviewed 7 out of 8 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
contents/winrm_kill.py New PID marker/preamble, output filtering, and remote termination orchestration.
contents/winrm-exec.py Integrates terminate-on-abort behavior (signal handling, wrapping commands, filtering marker output).
contents/winrm_session.py Exposes live WinRM handles (shell/command IDs) to support abort-time termination.
plugin.yaml Adds the new terminateonabort configuration option.
README.md Documents “Terminate On Abort” behavior and operational notes.
tests/test_winrm_kill.py Unit tests for PID parsing/stripping, streaming filter, and terminate orchestration.
contents/common.py Minor regex literal cleanup (raw strings).
.gitignore Ignores common Python build/test artifacts.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread contents/winrm-exec.py
Comment thread contents/winrm-exec.py Outdated
Comment on lines +438 to +442
# Emit any output still buffered in the marker filter (e.g. a final line with no
# trailing newline).
tail = marker_filter.flush()
if tail:
realstdout.write(tail)
Comment thread plugin.yaml
@ronaveva ronaveva merged commit c18e8ed into master Jun 16, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants