KushagraB424 opened a new pull request, #70950:
URL: https://github.com/apache/airflow/pull/70950
<!-- SPDX-License-Identifier: Apache-2.0
https://www.apache.org/licenses/LICENSE-2.0 -->
### 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?
- [X] Yes (please specify the tool below)
Generated-by: Antigravity IDE following the
[guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions)
--
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]