Skip to content

Prevent a broken job from stalling AWS Batch executor sync - #71380

Merged
o-nikolas merged 3 commits into
apache:mainfrom
AlexanderBLR:fix-batch-executor-sync-poisoning
Aug 17, 2026
Merged

o-nikolas merged 3 commits into
apache:mainfrom
AlexanderBLR:fix-batch-executor-sync-poisoning

Conversation

@AlexanderBLR

Copy link
Copy Markdown
Contributor

sync_running_jobs() handles all active jobs in a single pass, and sync() wraps the whole heartbeat in one catch-all. When handling of a single job raises, the exception aborts the entire cycle: the remaining jobs are not synced and, more importantly, attempt_submit_jobs() never runs. If the error is deterministic for that job, the executor stops submitting tasks entirely until the scheduler is restarted.

This is not hypothetical. BatchJobCollection.pop_by_id() raises KeyError before cleaning anything when the collection's bookkeeping is partially cleaned (e.g. a duplicate submission for the same workload key overwrites key_to_id, orphaning the older job id), so the failing job stays in active_workers forever and every subsequent heartbeat aborts at the same job. We hit exactly this in production (Airflow 3.2.1, apache-airflow-providers-amazon==9.31.0): one poisoned workload halted all Batch submissions cluster-wide (~20 Dags piling up in queued) until a scheduler restart, the only signal being Failed to sync AwsBatchExecutor repeating every heartbeat.

The fix:

  • each job in sync_running_jobs() is handled in its own try/except; an unexpected per-job error evicts that job and fails its workload instead of aborting the cycle;
  • new BatchJobCollection.remove_job() used for the eviction — a defensive removal that tolerates partially cleaned state, unlike pop_by_id().

Credential-type boto errors (ClientError / NoCredentialsError) still reach sync()'s handler unchanged: they can only be raised by _describe_jobs() / attempt_submit_jobs(), which sit outside the per-job block — nothing inside the block calls AWS.

Tests: two BatchJobCollection.remove_job() tests, eviction-with-isolation test (poisoned job evicted + failed, healthy job in the same cycle still succeeds), eviction survival when fail() itself raises, and a regression test for the production impact (attempt_submit_jobs() still runs when a tracked job cannot be synced).


Was generative AI tooling used to co-author this PR?
  • Yes — Claude Code (Fable 5)

Generated-by: Claude Code (Fable 5) following the guidelines


  • Read the Pull Request Guidelines for more information. Note: commit author/co-author name and email in commits become permanently public when merged.
  • For fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
  • When adding dependency, check compliance with the ASF 3rd Party License Policy.
  • For significant user-facing changes create newsfragment: {pr_number}.significant.rst, in airflow-core/newsfragments. You can add this file in a follow-up commit after the PR is created so you know the PR number.

A deterministic per-job error in sync_running_jobs() aborts every
heartbeat before attempt_submit_jobs(), halting all task submission
until the scheduler is restarted. Seen in production: a job whose
bookkeeping was partially cleaned made pop_by_id() raise KeyError
forever, wedging the whole executor.
@boring-cyborg boring-cyborg Bot added area:providers provider:amazon AWS/Amazon - related issues labels Aug 10, 2026
@boring-cyborg

boring-cyborg Bot commented Aug 10, 2026

Copy link
Copy Markdown

Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contributors' Guide
Here are some useful points:

  • Pay attention to the quality of your code (ruff, mypy and type annotations). Our prek-hooks will help you with that.
  • In case of a new feature add useful documentation (in docstrings or in docs/ directory). Adding a new operator? Check this short guide Consider adding an example Dag that shows how users should use it.
  • Consider using Breeze environment for testing locally, it's a heavy docker but it ships with a working Airflow and a lot of integrations.
  • Be patient and persistent. It might take some time to get a review or get the final approval from Committers.
  • Please follow ASF Code of Conduct for all communication including (but not limited to) comments on Pull Requests, Mailing list and Slack.
  • Be sure to read the Airflow Coding style.
  • Always keep your Pull Requests rebased, otherwise your build might fail due to changes not related to your commits.
    Apache Airflow is a community-driven project and together we are making it better 🚀.
    In case of doubts contact the developers at:
    Mailing List: [email protected]
    Slack: https://s.apache.org/airflow-slack

@vincbeck vincbeck left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good to me but @o-nikolas' opinion on this one would be great

…nc error If the error strikes after pop_by_id() has already removed the job from the collection (for example success() itself raising), the collection can no longer resolve the workload key and the workload would linger with no terminal state. Snapshot the key before handling each job and use it as a fallback during eviction.
… sync handling Per review: credential problems are executor-wide, not job-specific, so they must keep reaching sync()'s connection handling even if future code inside the per-job block calls boto, instead of evicting the job they happened to surface on.
@AlexanderBLR
AlexanderBLR requested a review from o-nikolas August 12, 2026 05:46
@o-nikolas

Copy link
Copy Markdown
Contributor

Ran tests again, let's see if they go green

@AlexanderBLR

Copy link
Copy Markdown
Contributor Author

Ran tests again, let's see if they go green

@o-nikolas the re-run came back green and all checks passed. Anything else you'd like me to address here? Thanks!

@o-nikolas
o-nikolas merged commit 7c34d30 into apache:main Aug 17, 2026
83 checks passed
@boring-cyborg

boring-cyborg Bot commented Aug 17, 2026

Copy link
Copy Markdown

Awesome work, congrats on your first merged pull request! You are invited to check our Issue Tracker for additional contributions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:providers provider:amazon AWS/Amazon - related issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants