You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Confusing log for long running tasks: "dependency 'Task Instance Not Running' FAILED: Task is in the running state" #16163
Kubernetes version (if you are using kubernetes) (use kubectl version): Any
Environment:
Cloud provider or hardware configuration: Any
OS (e.g. from /etc/os-release): Any
Kernel (e.g. uname -a): Any
Install tools: Any
Others: N/A
What happened:
This line in the TaskInstance log is very misleading. It seems to happen for tasks that take longer than one hour. When users are waiting for tasks to finish and see this in the log, they often get confused. They may think something is wrong with their task or with Airflow. In fact, this line is harmless. It's simply saying "the TaskInstance is already running so it cannot be run again".
{taskinstance.py:874} INFO - Dependencies not met for <TaskInstance: ... [running]>, dependency 'Task Instance Not Running' FAILED: Task is in the running state
{taskinstance.py:874} INFO - Dependencies not met for <TaskInstance: ... [running]>, dependency 'Task Instance State' FAILED: Task is in the 'running' state which is not a valid state for execution. The task must be cleared in order to be run.
What you expected to happen:
The confusion is unnecessary. This line should be silenced in the log. Or it should log something clearer.
How to reproduce it:
Any task that takes more than an hour to run has this line in the log.
Reacted by 張泰瑋(Chang Tai Wei), WendyOuyangIns, Bowen Kuo, Knab Analytics, johnny0120, Leah E. Cole, Alex Shires, Quentin Sommer, Shehroz Ahmed, Duc and 17 more
After some more investigation, it's very likely we see this log appearing an hour after a long running task started because of the default visibility_timeout setting in Celery. This code in default_celery.py sets visibility_timeout to 21600 only if the broker_url starts with redis or sqs. In our case we are using redis sentinels so it's still redis although the URL starts with sentinel. Therefore the visibility_timeout is left at 3600 which is the default according to celery documentation. The weird thing is that after I tried to manually change visibility_timeout to a very large integer in airflow.cfg, the same log still showed up exactly an hour after a task started. So it seems changing visibility_timeout in this case does not make any difference. Not sure if anyone experienced the same.
@david30907d maybe try changing visibility_timeout to a large number in your setup and see if it still happens after an hour. If it stops for you, it means visibility_timeout is probably the cause. There may be something wrong in our own setup causing changing visibility_timeout not to take effect.
In the case where the visibility timeout is reached, it's confusing that there is not a clear log line that the task has been killed for taking too long to complete.
(If that's indeed what is happening.)
@potiuk is it the case, that the Celery task is killed or is it simply no longer streaming logs into Airflow at that point?
I can give you the full logs right now, my task is a PythonOperator that inserts huge CSV files into Postgres. Concretely, I pass a method argument to the to_sql pandas method, in order to apply an upsert operation.
My task is always externally failed after 6 hours :/
@ashb@potiuk and others watching, if you experience this issue, it's just that your task is taking more than 6 hours, in most cases your task will continue running, but you can't see your logs until the task finishes or fails.
The visibility_timeout is the number of seconds celery will wait for an acknowledgment before it returns a task to the queue (for it to be picked up by another worker). But because task_acks_late is True, airflow's celery workers will not acknowledge tasks until AFTER the task has finished. Hence, if a task takes more than visibility_timeout seconds to finish, celery will tell another worker to start this task.
When this happens, the new instance of this task will realize the task is still running on the old worker (it's not failed, and is even heart-beating the TaskInstance), and will correctly wait (because a task can not be "running" in two places). But now the airflow UI only shows the logs for this new "phantom task", which will always be:
{taskinstance.py:874} INFO - Dependencies not met for <TaskInstance: ... [running]>, dependency 'Task Instance Not Running' FAILED: Task is in the running state
{taskinstance.py:874} INFO - Dependencies not met for <TaskInstance: ... [running]>, dependency 'Task Instance State' FAILED: Task is in the 'running' state which is not a valid state for execution. The task must be cleared in order to be run.
Effectively, this issue is the result of celery taking matters into its own hands (outside of the control of the airflow scheduler), and telling a new worker to start the task which is still running on the old worker.
Celery's purpose of task_acks_late is to prevent "zombie" tasks that take too long. But Airflow already has "heartbeat" checks for zombie tasks, so there is probably no need to have celery re-issuing tasks.
Setting task_acks_late to False, and visibility_timeout to a much lower number (like 300 sec), will also have the added benefit of detecting celery transport failures
Reacted by Malthe Borch, Katrina Pettitt, dKosarevsky, Anatoly, Bhaskoro Muthohar, kavinnd, Ryan Hatter, Kevin Letupe, Jingyuan Zhang, nghilethanh-atherlabs and 2 more
Late ack means the task messages will be acknowledged after the task has been executed, not right before (the default behavior).
It seems that it's a way to ensure at-least-once processing rather than at-most-once. I would say that since Airflow does retrying on its own accord, we want the latter which is why it probably should remain disabled.
@thesuperzapper@potiuk , We are also facing the same issue, however in our case the previous set of logs are getting trimmed and the logs start with
{taskinstance.py:874} INFO - Dependencies not met for <TaskInstance: ... [running]>, dependency 'Task Instance Not Running' FAILED: Task is in the running state
{taskinstance.py:874} INFO - Dependencies not met for <TaskInstance: ... [running]>, dependency 'Task Instance State' FAILED: Task is in the 'running' state which is not a valid state for execution. The task must be cleared in order to be `run.
Logs of previously running task append post these lines.
I am seeing this as well with Airflow v2.5.1 (not using kubernetes) w/Celery Executor. We also utilize s3 remote logging, and observe regular log for the first hour, then Dependencies not met for <TaskInstance log is written to s3 and only that log is visible until the task completes (since airflow checks remote log first).
Once the task completes, the "real" log for the original task is appended below the Dependencies not met for <TaskInstance log...
Activity
david30907d commentedon Jun 23, 2021
I bumped into this issue and I misunderstood until now 😅
thanks for pointing out it's okay to wait
yuqian90 commentedon Jun 26, 2021
After some more investigation, it's very likely we see this log appearing an hour after a long running task started because of the default
visibility_timeoutsetting in Celery. This code in default_celery.py setsvisibility_timeoutto 21600 only if the broker_url starts with redis or sqs. In our case we are using redis sentinels so it's still redis although the URL starts withsentinel. Therefore thevisibility_timeoutis left at 3600 which is the default according to celery documentation. The weird thing is that after I tried to manually changevisibility_timeoutto a very large integer in airflow.cfg, the same log still showed up exactly an hour after a task started. So it seems changingvisibility_timeoutin this case does not make any difference. Not sure if anyone experienced the same.@david30907d maybe try changing
visibility_timeoutto a large number in your setup and see if it still happens after an hour. If it stops for you, it meansvisibility_timeoutis probably the cause. There may be something wrong in our own setup causing changingvisibility_timeoutnot to take effect.david30907d commentedon Jun 26, 2021
@yuqian90 thanks, very useful information. I'll give
celery_broker_transport_optionsa shot!potiuk commentedon Jun 28, 2021
Moved it to 2.2 now - I guess we have not addressed it yet in 2.1.1
malthe commentedon Jul 2, 2021
In the case where the visibility timeout is reached, it's confusing that there is not a clear log line that the task has been killed for taking too long to complete.
(If that's indeed what is happening.)
@potiuk is it the case, that the Celery task is killed or is it simply no longer streaming logs into Airflow at that point?
potiuk commentedon Jul 2, 2021
Not sure. Needs investigation
61 remaining items
medina325 commentedon Mar 13, 2023
I can give you the full logs right now, my task is a PythonOperator that inserts huge CSV files into Postgres. Concretely, I pass a
methodargument to theto_sqlpandas method, in order to apply an upsert operation.My task is always externally failed after 6 hours :/
polidore commentedon Mar 17, 2023
same issue. a task that used to take ~4 hours is now taking ~8 hours since I switched to celery. it seems maybe on the retry it finishes?
AndreiArion commentedon Mar 17, 2023
In our context (GCP Airflow 2.2.5 #16163 (comment)) the problem was correlated with Kubernetes pods being evicted due of lacking ressources. After scaling up our kubernetes cluster and updating to Airflow 2.4.3 (+ google-providers=8.8.0 due to https://stackoverflow.com/questions/74730471/gcstobigqueryoperator-not-working-in-composer-2-1-0-airflow-2-3-4/75319966#75319966 ) we have not seen this problem in the last month since upgrading .
As we no longer have pods evictions I cannot conclude if the issue was fixed in Airflow or the workaround was sufficient (preventing Airflow workers to be killed).
MattiaGallegati commentedon Apr 19, 2023
Hello, are there any new evidence on this bug?
thesuperzapper commentedon May 26, 2023
@ashb @potiuk and others watching, if you experience this issue, it's just that your task is taking more than 6 hours, in most cases your task will continue running, but you can't see your logs until the task finishes or fails.
As a temporary fix, you can increase the time it takes for this to happen by increasing the value of
AIRFLOW__CELERY_BROKER_TRANSPORT_OPTIONS__VISIBILITY_TIMEOUTto something like86400(24 hours).I believe I have uncovered the cause of this issue and would appreciate feedback.
The question is, why are we losing the logs after 6 hours?
I believe this is because of a slightly complex combination of celery configs:
task_acks_late=Truebroker_transport_options.visibility_timeout=21600The
visibility_timeoutis the number of seconds celery will wait for an acknowledgment before it returns a task to the queue (for it to be picked up by another worker). But becausetask_acks_lateisTrue, airflow's celery workers will not acknowledge tasks until AFTER the task has finished. Hence, if a task takes more thanvisibility_timeoutseconds to finish, celery will tell another worker to start this task.When this happens, the new instance of this task will realize the task is still running on the old worker (it's not failed, and is even heart-beating the TaskInstance), and will correctly wait (because a task can not be "running" in two places). But now the airflow UI only shows the logs for this new "phantom task", which will always be:
Effectively, this issue is the result of celery taking matters into its own hands (outside of the control of the airflow scheduler), and telling a new worker to start the task which is still running on the old worker.
Setting our
task_acks_latetoFalsewill likely fix this issue. However, I am not sure what the other implications would be, as I can see that it has been set toTruefor most of Airflow's existence, it was set toTruein this commit from 2015.Celery's purpose of
task_acks_lateis to prevent "zombie" tasks that take too long. But Airflow already has "heartbeat" checks for zombie tasks, so there is probably no need to have celery re-issuing tasks.Setting
task_acks_latetoFalse, andvisibility_timeoutto a much lower number (like300sec), will also have the added benefit of detecting celery transport failuresFinally, I want to highlight that Airflow's docs are confusing about what the default
visibility_timeoutis, because this piece of code will set it to21600, whenAIRFLOW__CELERY_BROKER_TRANSPORT_OPTIONS__VISIBILITY_TIMEOUTisNone, which is different from the celery default of3600potiuk commentedon Jun 8, 2023
Care for submitting a PR @thesuperzapper ? That would be a small thing to give back for the years of business you have on top of Airflow
malthe commentedon Jun 9, 2023
According to the Celery docs:
It seems that it's a way to ensure at-least-once processing rather than at-most-once. I would say that since Airflow does retrying on its own accord, we want the latter which is why it probably should remain disabled.
thesuperzapper commentedon Jun 10, 2023
@potiuk @malthe here is the PR to change
task_acks_latetoFalse:task_acks_late#31829Let's discuss the implications and do some testing in that thread.
sourabp commentedon Sep 26, 2023
@thesuperzapper @potiuk , We are also facing the same issue, however in our case the previous set of logs are getting trimmed and the logs start with
Logs of previously running task append post these lines.
Airflow version: 2.6.0
richard-iovanisci commentedon Oct 24, 2023
I am seeing this as well with Airflow v2.5.1 (not using kubernetes) w/Celery Executor. We also utilize s3 remote logging, and observe regular log for the first hour, then
Dependencies not met for <TaskInstancelog is written to s3 and only that log is visible until the task completes (since airflow checks remote log first).Once the task completes, the "real" log for the original task is appended below the
Dependencies not met for <TaskInstancelog...