Skip to content

Airflow task is marked as succeeded on the EcsTaskFailToStart exception #52943

@vladimirbinshtok

Description

@vladimirbinshtok

Apache Airflow Provider(s)

amazon

Versions of Apache Airflow Providers

When using EcsRunTaskOperator, if an ECS task fails to start (e.g., due to resource constraints or misconfiguration), the _check_success_task method raises EcsTaskFailToStart. The @AwsBaseHook.retry(should_retry_eni) decorator retries this exception. However, the arn is set to None, so the function exits as success.

@AwsBaseHook.retry(should_retry_eni)
def _check_success_task(self) -> None:
    if not self.client or not self.arn:
        return

    response = self.client.describe_tasks(cluster=self.cluster, tasks=[self.arn])
    self.log.info("ECS Task stopped, check status: %s", response)

    if len(response.get("failures", [])) > 0:
        raise AirflowException(response)

    for task in response["tasks"]:
        if task.get("stopCode", "") == "TaskFailedToStart":
            # Reset task arn here otherwise the retry run will not start
            # a new task but keep polling the old dead one
            # I'm not resetting it for other exceptions here because
            # EcsTaskFailToStart is the only exception that's being retried at the moment
            self.arn = None
            raise EcsTaskFailToStart(f"The task failed to start due to: {task.get('stoppedReason', '')}")

Apache Airflow version

2.7.2

Operating System

Ubuntu 22.04

Deployment

Other

Deployment details

No response

What happened

The Airflow task is marked as successful even though the ECS task never started successfully.

What you think should happen instead

The Airflow task should be marked as failed if the ECS task fails to start and all retries are exhausted.

How to reproduce

Create a misconfigured ECS Task definition

Anything else

No response

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Code of Conduct

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions