Skip to content

Skip stale failure callbacks so duplicate zombie requests don't consume retries (2.5.1) - #38

Draft
noorcyang wants to merge 1 commit into
masterfrom
chi/zombie-callback-skip-stale
Draft

noorcyang wants to merge 1 commit into
masterfrom
chi/zombie-callback-skip-stale

Conversation

@noorcyang

Copy link
Copy Markdown

Problem

Zombie detection (SchedulerJob._find_zombies) sends a TaskCallbackRequest while the TI is RUNNING. The TI only leaves RUNNING when the DAG processor handles that request, so the scheduler can enqueue several requests for the same attempt before the first is processed. The DAG processor then calls handle_failure once per request:

  1. Request Ddb scheduler lock #1: TI RUNNING, try 1 ≤ max_tries 1 → UP_FOR_RETRY.
  2. Request bump future #2: TI is now UP_FOR_RETRY, so try_number reads 2 > max_tries → FAILED. The retry is silently consumed.

Prod UK, 2026-11-19. A metadb row-lock storm on lake-dms-cdc-fileloader-dag made ~70 tasks fail their final state commit after their work had already succeeded. The scheduler logged Detected zombie job 2–3× per TI, and the processor marked them UP_FOR_RETRY, then FAILED. About 50 tasks with retries=1 stayed FAILED until someone cleared them by hand ~80 min later. RC: ~/1workspace/uk-fileloader-dagrun-lock-rc-2026-11-19.md (local).

Fix

DagFileProcessor._execute_task_callbacks is now a no-op when the TI is no longer in the state and attempt (try_number) recorded in the request's SimpleTaskInstance. It logs Skipping stale failure callback … instead.

That covers both failure-callback senders in 2.5.1:

  • Zombies, created while RUNNING.
  • "Killed externally" (_process_executor_events), created while QUEUED.

A request still matching the TI's current state and attempt is handled exactly as before.

Upstream

Tests

Run on SQLite, Python 3.9, apache-airflow==2.5.1 constraints, fork code on PYTHONPATH.

  • New test_execute_on_failure_callbacks_skips_stale_request: stale request when the TI is already up_for_retry / failed / success, or the next attempt is running. Asserts handle_failure is not called.
  • New test_duplicate_zombie_callbacks_do_not_consume_retry: unmocked. Two identical zombie requests for a retries=1 TI must leave it UP_FOR_RETRY.
  • Both new tests fail without the patch (5/5) and pass with it.
  • tests/dag_processing/test_processor.py: 37 passed.
  • tests/jobs/test_scheduler_job.py -k "zombie or callback or killed_externally": 23 passed.
  • Not run: MySQL backend, full suite.

Not included

  • No version bump (2.5.1+affirm4 → affirm5) and no airflow-att image bump. Say if you want them here.

🤖 Generated with Claude Code

…me retries

Zombie detection sends a TaskCallbackRequest while the TI is RUNNING, but the TI
only leaves RUNNING once the DAG processor handles that request. The scheduler
can therefore enqueue several requests for the same attempt. The first one
moves the TI to UP_FOR_RETRY; each duplicate then calls handle_failure again,
which sees the bumped try number and marks the TI FAILED, silently consuming
the retry.

In prod UK on 2026-11-19 this left ~50 lake-dms-cdc-fileloader-dag tasks
(retries=1) FAILED after a metadb lock storm; they needed a manual clear.

Make _execute_task_callbacks a no-op when the TI is no longer in the state and
attempt (try_number) recorded in the request's SimpleTaskInstance. That covers
both senders in 2.5.1: zombies (RUNNING) and killed-externally (QUEUED).
Upstream fixed the duplicate-request case in Airflow 3.4.0 (apache#68008,
closes apache#42553); 2.x, including 2.10.5, still has the bug.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Affirm-Session: 2a95b7fd-f6ac-49d8-aaf6-c568590e6efd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Same task instance attempt is detected as a zombie multiple times and fails without retries

1 participant