Repository navigation
Enforce the Dag import timeout from the task supervisor side - #74571
Andrushika wants to merge 9 commits into
Conversation
Move the get_dagbag_import_timeout policy lookup, its fallback when airflow settings cannot be imported, and the int/float check into a module-level function, so the task runner can resolve the same value for a Dag file before it is parsed.
The task process needs to drop the supervisor's deadline once a phase it armed is over, so a value of 0 now means "no deadline" instead of being rejected. The supervisor's timeout log line no longer names execution_timeout, since it will also fire for the Dag parse phase. SetExecutionTimeout has not been released yet, so the in-progress supervisor schema version only gets a note instead of a VersionChange.
Before parsing a plain Python Dag file, the task process now sends the file's dagbag_import_timeout to the supervisor and clears it once parsing is done, so a parse stuck in native code is stopped from outside like an execute() that overruns execution_timeout. The value comes from the same get_dagbag_import_timeout policy the importer uses for the file's own alarm. Nothing is sent when the policy disables the timeout. Zipped Dags are not armed: the importer gives each member its own timeout, so a single deadline for the archive could be too short.
The message now carries the Dag import timeout as well as the task's execution_timeout, and 0 clears the deadline, so the old name described only one of its uses. It has not been released yet, so this is the last point where the name can change without a migration.
cf21b7e to
fcdaddc
Compare
| what = StartupDetails( | ||
| ti=TaskInstance( | ||
| id=uuid7(), | ||
| task_id="a", | ||
| dag_id="super_basic", | ||
| run_id="c", | ||
| try_number=1, | ||
| dag_version_id=uuid7(), | ||
| queue="default", | ||
| ), | ||
| dag_rel_path="super_basic.py", | ||
| bundle_info=BundleInfo(name="my-bundle", version=None), | ||
| ti_context=make_ti_context(), | ||
| start_date=timezone.utcnow(), | ||
| sentry_integration="", | ||
| ) |
There was a problem hiding this comment.
I kinda want to turn the StartupDetails setup into a common fixture, since about 20 tests in this file build it inline.
That would be a separate follow-up though, happy to do it if maintainers think it's worth it
|
Another related: #69713 (it's a one-line change, ready for review but was closed due to the PR number limit policy) |
This reverts commit fcdaddc.
…meout # Conflicts: # airflow-core/docs/core-concepts/tasks.rst # task-sdk/src/airflow/sdk/execution_time/supervisor.py # task-sdk/tests/task_sdk/execution_time/test_supervisor.py # task-sdk/tests/task_sdk/execution_time/test_task_runner.py
The 2026-10-30 version shipped in Task SDK 1.4.0 with timeout_seconds > 0, so accepting 0 to clear the deadline belongs to the in-progress version.
|
Fork CI: green. CI for the latest commit passed in your fork. The pull request is ready for maintainer review. Pull requests from contributors run their CI in the contributor's own fork. GitHub Actions is free and has no minute limit on public forks, while the CI capacity of the Apache Software Foundation is shared by every ASF project and is finite. Fork CI tested this branch merged with How this works: CI in your fork. This comment was posted automatically by the fork CI monitor from templates drafted with an AI-assisted tool, so it may contain mistakes. An Apache Airflow maintainer, a real person, will review the pull request once its fork CI is green. Why the first pass is automated. |
Why
#73806 lets the task supervisor stop a task process that runs past
execution_timeout. The supervisor arms that deadline right beforeexecute().Before
execute(), the task process parses the Dag file. During parsing, only the process's owndagbag_import_timeoutalarm applies.That alarm is a SIGALRM handler, so it never fires when the import is stuck in native code. Nothing outside the process watches this window.
What
Following the
SetTimeout(0)suggestion in #73806, the task process sendsSetExecutionTimeoutwith the file'sdagbag_import_timeoutbefore it parses a plain Python Dag file. Right after parsing, it sendsSetExecutionTimeout(0), which clears the deadline.The value comes from the
get_dagbag_import_timeoutcluster policy, with the same file path that the importer uses. If the policy disables the timeout, the task process sends nothing.Zipped Dags are not armed. The importer gives each member of the archive its own timeout, so one deadline for the whole archive can be too short.
timeout_secondsaccepts0for the clear. Supervisor schema version 2027-02-28 records this, because 2026-10-30 shipped in Task SDK 1.4.0 withtimeout_seconds > 0.Cost per task start, measured in breeze with a real supervisor (median of 2000 iterations, 3 runs):
related: #73806
Was generative AI tooling used to co-author this PR?
Generated-by: Claude Code (Opus 5.5) following the guidelines