Airflow tasks get stuck at "queued" status and never gets running
Asked Answered
P

8

35

I'm using Airflow v1.8.1 and run all components (worker, web, flower, scheduler) on kubernetes & Docker. I use Celery Executor with Redis and my tasks are looks like:

(start) -> (do_work_for_product1)
     ├  -> (do_work_for_product2)
     ├  -> (do_work_for_product3)
     ├  …

So the start task has multiple downstreams. And I setup concurrency related configuration as below:

parallelism = 3
dag_concurrency = 3
max_active_runs = 1

Then when I run this DAG manually (not sure if it never happens on a scheduled task) , some downstreams get executed, but others stuck at "queued" status.

If I clear the task from Admin UI, it gets executed. There is no worker log (after processing some first downstreams, it just doesn't output any log).

Web server's log (not sure worker exiting is related)

/usr/local/lib/python2.7/dist-packages/flask/exthook.py:71: ExtDeprecationWarning: Importing flask.ext.cache is deprecated, use flask_cache instead.
  .format(x=modname), ExtDeprecationWarning
[2017-08-24 04:20:56,496] [51] {models.py:168} INFO - Filling up the DagBag from /usr/local/airflow_dags
[2017-08-24 04:20:57 +0000] [27] [INFO] Handling signal: ttou
[2017-08-24 04:20:57 +0000] [37] [INFO] Worker exiting (pid: 37)

There is no error log on scheduler, too. And a number of tasks get stuck is changing whenever I try this.

Because I also use Docker I'm wondering if this is related: https://github.com/puckel/docker-airflow/issues/94 But so far, no clue.

Has anyone faced with a similar issue or have some idea what I can investigate for this issue...?

Pearly answered 24/8, 2017 at 4:33 Comment(7)
Hi @Norio, we are having the similar issue that tasks in queue but scheduler seems forgot some of them. When I use airflow scheduler again, they have been picked up. I am also using 1.8.1, kubernetes and Docker, but with LocalExecutor, same issue here.Castanets
@Castanets Thank you for the info. I utilize this shell github.com/apache/incubator-airflow/blob/… to automatically restart scheduler without relying on k8s's back off, so in my case scheduler should be periodically re-spawned but not pick some tasks forever... very weird.Pearly
super, thanks for sharing, very wired, I will keep you in loop if I found something, but it looks like this is the solution for now.Castanets
I'm having a similar problem with airflow and using LocalExecutor. My setup is ismilar to the one @Castanets has. Did anyone find anything to try here?Eck
Just resolved my case which doesn't seem to be like yours but worth sharing. I was working with the logs/ folder and without noticing all ownership of folders changed. For this reason, Airflow was not able to write in log files and task kept getting stuck on queued state. Changing ownership of all files back to airflow user brought the application to normal. sudo chown -R airflow:airflow logs/Eck
Please look at the stuck/queued task instance logs and provide those. We see this in our environment and it seems that its due to a dagbag import timeout that happens when the server is overly busy. See also this bug: issues.apache.org/jira/browse/…Hangnail
Check the container of your Airflow worker with docker ps and if it's unhealthy, stop it with docker stop <container_id>, remove it with docker rm <container_id>, then start it again with docker run <image_name>Cirone
M
10

Tasks getting stuck is, most likely, a bug. At the moment (<= 1.9.0alpha1) it can happen when a task cannot even start up on the (remote) worker. This happens for example in the case of an overloaded worker or missing dependencies.

This patch should resolve that issue.

It is worth investigating why your tasks do not get a RUNNING state. Setting itself to this state is first thing a task does. Normally the worker does log before it starts executing and it also reports and errors. You should be able to find entries of this in the task log.

edit: As was mentioned in the comments on the original question in case one example of airflow not being able to run a task is when it cannot write to required locations. This makes it unable to proceed and tasks would get stuck. The patch fixes this by failing the task from the scheduler.

Mcandrew answered 22/10, 2017 at 19:52 Comment(1)
We are seeing this issue with 1.9.0 tasks get queued but never go to running state unless done manually from the UIGenerative
C
3

We have a solution and want to share it here before 1.9 becomes official. Thanks for Bolke de Bruin updates on 1.9. in my situation before 1.9, currently we are using 1.8.1 is to have another DAG running to clear the task in queue state if it stays there for over 30 mins.

Castanets answered 23/10, 2017 at 16:25 Comment(1)
Do you have the code of this DAG available somewhere by any chance please? I also have this issue and will take some time before I can migrate to a newer version of Airflow.Josephson
F
3

I have been working on the same docker image puckel. My issue was resolved by :

Replacing

 result_backend = db+postgresql://airflow:airflow@postgres/airflow

with

celery_result_backend = db+postgresql://airflow:airflow@postgres/airflow

which I think is updated in the latest pull by puckel. The change was reverted around in Feb 2018 and your comment was made in January.

Fabio answered 20/4, 2018 at 18:19 Comment(1)
I am using puckel images, and I want to run some command on containers; for instance airflow dag_state spark_python, but I am encounter following error: airflow.exceptions.AirflowConfigException: error: cannot use sqlite with the CeleryExecutor, do you have any idea, why I cannot runRebuttal
L
3

Please try airflow scheduler, airflow worker command.

I think airflow worker calls each task, airflow scheduler calls between two tasks.

Leanneleanor answered 4/7, 2018 at 11:34 Comment(1)
This might not be a resolution to the problem, but atleast by running these commands you can come to know what the problem, like if they error out somethingUlphiah
Q
2

I arrived here after Googling and in my case with MWAA, my Airflow was running with limited resources quite many tasks. I observed several Airflow DAGs in a Queued State, so I thought it was an issue of resources.

Increasing the allocated resources to the Environment Class for my Airflow instance solved the issue: DAGs got unblocked and resumed working.

Quag answered 19/1, 2023 at 14:30 Comment(0)
F
1

In my case, all Airflow tasks got stuck and none of them were running. Below are the steps I have done to fix it:

  1. Kill all airflow processes, using $ kill -9 <pid>
  2. Kill all celery processes, using $ pkill celery
  3. Increses count for celery's worker_concurrency, parallelism, dag_concurrency configs in airflow.cfg file.
  4. Starting airflow, first check if airflow webserver automatically get started, as in my case, it is running through Gunicorn otherwise start using $ airflow webserver &
  5. Start airflow scheduler $ airflow scheduler
  6. Start airflow worker $ airflow worker
  7. Try to run a job.
Forecastle answered 13/1, 2021 at 16:12 Comment(0)
F
0

My tasks were stuck in state:queued because I was hitting concurrency limits.

These are defined within ~/airflow/airflow.cfg

parallelism = 16
max_active_tasks_per_dag = 16
max_active_runs_per_dag = 16

Be aware that each task instance appears to be using 3 x 128 MB RAM on my machine

Fimble answered 19/3 at 11:58 Comment(0)
M
0

I'm running Airflow version 2.4.3 and seemed to have got the same issue. But I resolved it by clearing the metadata database airflow db reset - not sure if this is the best solution, but just in case anyone wants a potentially quick way of resolving queued tasks that are not running.

PLEASE NOTE: resetting the metadata will remove all DAG history and previous runs. It also removes any users created as well.

Mew answered 16/6 at 7:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.