Skip to content

Each scheduler may process same zombie tasks in HA mode #25843

Closed

Description

@pingzh

Apache Airflow version

main (development)

What happened

def _find_zombies(self, session: Session) -> None:
"""
Find zombie task instances, which are tasks haven't heartbeated for too long
or have a no-longer-running LocalTaskJob, and create a TaskCallbackRequest
to be handled by the DAG processor.
"""
self.log.debug("Finding 'running' jobs without a recent heartbeat")
limit_dttm = timezone.utcnow() - timedelta(seconds=self._zombie_threshold_secs)
zombies = (
session.query(TaskInstance, DagModel.fileloc)
.with_hint(TI, 'USE INDEX (ti_state)', dialect_name='mysql')
.join(LocalTaskJob, TaskInstance.job_id == LocalTaskJob.id)
.join(DagModel, TaskInstance.dag_id == DagModel.dag_id)
.filter(TaskInstance.state == TaskInstanceState.RUNNING)
.filter(
or_(
LocalTaskJob.state != State.RUNNING,
LocalTaskJob.latest_heartbeat < limit_dttm,
)
)
.filter(TaskInstance.queued_by_job_id == self.id)
.all()
)
if zombies:
self.log.warning("Failing (%s) jobs without heartbeat after %s", len(zombies), limit_dttm)
for ti, file_loc in zombies:
request = TaskCallbackRequest(
full_filepath=file_loc,
simple_task_instance=SimpleTaskInstance.from_ti(ti),
msg=f"Detected {ti} as zombie",
)
self.log.error("Detected zombie job: %s", request)
self.executor.send_callback(request)
Stats.incr('zombies_killed')

_find_zombies should also support HA. Each scheduler tries to find all zombie tasks. When there are more than one schedulers, it might cause issues.

What you think should happen instead

No response

How to reproduce

No response

Operating System

Apple M1 Max, version: 12.2

Versions of Apache Airflow Providers

No response

Deployment

Other

Deployment details

NA

Anything else

No response

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Code of Conduct

Activity

  1. eladkal commented on Aug 20, 2022

    @eladkal
    Contributor

    Can you try 2.3.4RC1 #25846?
    #24906 probably fixed it?

  2. potiuk commented on Aug 20, 2022

    @potiuk
    Member

    Yep. This is fixed in #24906

  3. pingzh commented on Aug 22, 2022

    @pingzh
    Author

    nice, thanks @eladkal and @potiuk

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions