Forward termination signals from supervisor to task subprocess (#61627)
When a Kubernetes worker pod receives SIGTERM (spot interruption, scaling down, rolling update), the signal is delivered to the supervisor process (PID 1 in the container). The supervisor has no signal handler installed and exits with default behavior, leaving the task subprocess orphaned without ever calling the operator's `on_kill()` hook. Spawned resources (pods, subprocesses, etc.) are never cleaned up. The task subprocess already has a SIGTERM handler registered in `task_runner.py` that calls `on_kill()`, but the signal never reaches it because the supervisor process terminates first. Install SIGTERM/SIGINT signal handlers in `ActivitySubprocess.wait()` that forward the received signal to the task subprocess via `os.kill()`. The child's existing handler then calls `on_kill()` as expected, restoring the Airflow 2 behavior. Handlers are saved before `_monitor_subprocess()` and restored in a `finally` block. Placing the handler in `ActivitySubprocess.wait()` (rather than `supervise_task`) makes the forwarding work for any coordinator that uses `ActivitySubprocess` and keeps the handler colocated with the process it forwards to. Fixes: #58936 Signed-off-by: André Ahlert <andre@aex.partners>
A
André Ahlert committed
4f76227dbd62f6d0d28cbc7580d090b5236fd30d
Parent: 120b49a
Committed by GitHub <noreply@github.com>
on 5/30/2026, 10:02:38 PM