Skip to content

Make Task SDK supervisor subprocess a session leaderFix supervisor session leader - #70950

Open
KushagraB424 wants to merge 1 commit into
apache:mainfrom
KushagraB424:fix-supervisor-session-leader
Open

Make Task SDK supervisor subprocess a session leaderFix supervisor session leader#70950
KushagraB424 wants to merge 1 commit into
apache:mainfrom
KushagraB424:fix-supervisor-session-leader

Conversation

@KushagraB424

Copy link
Copy Markdown
Contributor

Background & Problem

In task-sdk/src/airflow/sdk/execution_time/supervisor.py, the _subprocess_main function is the entry point for the child process that runs the user's task code. An existing TODO comment indicated that this child process should be made a session leader.

If the process is not a session leader, it remains in the same process group as the parent supervisor. This means that if a signal (like SIGINT or SIGTERM) is sent to the parent process group, both the parent and the child would receive it independently, potentially leading to double-firing of signal handlers and race conditions during shutdown or interruption.

The Solution

This PR resolves the TODO by making the child process a session leader immediately upon startup.

We introduced a call to os.setsid() inside a try...except OSError block, guarded by hasattr(os, "setsid") to ensure cross-platform compatibility (especially for Windows environments where setsid might not be available). This isolates the child process into its own session and process group, ensuring that signals are handled explicitly through the supervisor's lifecycle management rather than broadcasted by the OS terminal.

Impacted Files

[MODIFY] task-sdk/src/airflow/sdk/execution_time/supervisor.py

Testing & Verification

  • The changes gracefully fall back if os.setsid() is unavailable or fails.
  • CI/CD pipelines (via breeze and pre-commit) will verify that syntax is correct and that process isolation continues to function properly across supported operating systems.

closes: #70949


Was generative AI tooling used to co-author this PR?
  • Yes (please specify the tool below)

Generated-by: Antigravity IDE following the guidelines

@boring-cyborg boring-cyborg Bot added area:API Airflow's REST/HTTP API area:task-sdk labels Aug 2, 2026
@KushagraB424
KushagraB424 force-pushed the fix-supervisor-session-leader branch from 0d80ca8 to 9704b18 Compare August 2, 2026 21:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:API Airflow's REST/HTTP API area:task-sdk

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make Task SDK supervisor subprocess a session leader

1 participant