shivaam opened a new pull request, #64737:
URL: https://github.com/apache/airflow/pull/64737
## Summary
The scheduler's deadline-check loop in `scheduler_job_runner.py` selected
expired, unhandled `Deadline` rows without any row-level lock. Under HA
deployments with multiple scheduler replicas, two schedulers could read the
same row concurrently, both call `handle_miss`, and both create duplicate
`Trigger` records — causing the deadline breach callback to fire multiple
times.
This change wraps the SELECT in `with_row_locks(..., of=Deadline,
skip_locked=True, key_share=False)`, so the first scheduler to reach a row
holds a `FOR UPDATE` lock until commit, and any other scheduler silently
skips that row. `key_share=False` is required because the default
`FOR KEY SHARE` does not conflict with itself — two concurrent schedulers
would otherwise still both grab the row.
## Test plan
- Added one regression test
(`test_expired_deadline_locked_by_other_scheduler_is_skipped`): opens an
independent session via `create_session(scoped=False)`, acquires the same
row lock the scheduler uses, and verifies the real scheduler loop skips
the locked row (`handle_miss` is never called).
- Verified the new test **fails without the fix** (reverting the scheduler
change produces `AssertionError: Expected 'handle_miss' to not have been
called. Called 1 times`) and **passes with the fix** applied.
- Re-ran the existing `test_process_expired_deadlines` and
`test_process_expired_deadlines_no_deadlines_found` with the fix applied
to confirm no regression to the happy path / empty-table edge cases.
- All runs green against Postgres 14 via Breeze.
- The new test is skipped on SQLite (single-writer DB, no row locking).
closes: #64710
---
##### Was generative AI tooling used to co-author this PR?
- [X] Yes — Claude Code (claude-opus-4-6)
Generated-by: Claude Code (claude-opus-4-6) 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]