airflow: Executor reports task instance (...) finished (failed) although the task says it's queued
Apache Airflow version
2.9.1
If “Other Airflow 2 version” selected, which one?
No response
What happened?
[2024-05-20T12:03:24.184+0000] {task_context_logger.py:91} ERROR - Executor reports task instance
<TaskInstance: (...) scheduled__2024-05-20T11:00:00+00:00 map_index=15 [queued]>
finished (failed) although the task says it's queued. (Info: None) Was the task killed externally?
What you think should happen instead?
No response
How to reproduce
I am not sure, unfortunately. But every day I see my tasks being killed randomly without good reasoning behind why it got killed/failed.
Operating System
Ubuntu 22.04.4 LTS
Versions of Apache Airflow Providers
apache-airflow==2.9.1
apache-airflow-providers-amazon==8.20.0
apache-airflow-providers-celery==3.6.2
apache-airflow-providers-cncf-kubernetes==8.1.1
apache-airflow-providers-common-io==1.3.1
apache-airflow-providers-common-sql==1.12.0
apache-airflow-providers-docker==3.10.0
apache-airflow-providers-elasticsearch==5.3.4
apache-airflow-providers-fab==1.0.4
apache-airflow-providers-ftp==3.8.0
apache-airflow-providers-google==10.17.0
apache-airflow-providers-grpc==3.4.1
apache-airflow-providers-hashicorp==3.6.4
apache-airflow-providers-http==4.10.1
apache-airflow-providers-imap==3.5.0
apache-airflow-providers-microsoft-azure==10.0.0
apache-airflow-providers-mongo==4.0.0
apache-airflow-providers-mysql==5.5.4
apache-airflow-providers-odbc==4.5.0
apache-airflow-providers-openlineage==1.7.0
apache-airflow-providers-postgres==5.10.2
apache-airflow-providers-redis==3.6.1
apache-airflow-providers-sendgrid==3.4.0
apache-airflow-providers-sftp==4.9.1
apache-airflow-providers-slack==8.6.2
apache-airflow-providers-smtp==1.6.1
apache-airflow-providers-snowflake==5.4.0
apache-airflow-providers-sqlite==3.7.1
apache-airflow-providers-ssh==3.10.1
Deployment
Docker-Compose
Deployment details
Client: Docker Engine - Community
Version: 26.1.3
Context: default
Debug Mode: false
Plugins:
buildx: Docker Buildx (Docker Inc.)
Version: v0.14.0
Path: /usr/libexec/docker/cli-plugins/docker-buildx
compose: Docker Compose (Docker Inc.)
Version: v2.27.0
Path: /usr/libexec/docker/cli-plugins/docker-compose
scan: Docker Scan (Docker Inc.)
Version: v0.23.0
Path: /usr/libexec/docker/cli-plugins/docker-scan
Server:
Containers: 30
Running: 25
Paused: 0
Stopped: 5
Images: 36
Server Version: 26.1.3
Storage Driver: overlay2
Backing Filesystem: btrfs
Supports d_type: true
Using metacopy: false
Native Overlay Diff: true
userxattr: false
Logging Driver: json-file
Cgroup Driver: systemd
Cgroup Version: 2
Plugins:
Volume: local
Network: bridge host ipvlan macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file local splunk syslog
Swarm: inactive
Runtimes: io.containerd.runc.v2 runc
Default Runtime: runc
Init Binary: docker-init
containerd version: e377cd56a71523140ca6ae87e30244719194a521
runc version: v1.1.12-0-g51d5e94
init version: de40ad0
Security Options:
apparmor
seccomp
Profile: builtin
cgroupns
Kernel Version: 5.15.0-107-generic
Operating System: Ubuntu 22.04.4 LTS
OSType: linux
Architecture: x86_64
CPUs: 80
Total Memory: 62.33GiB
Name: troy
ID: UFMO:HODB:7MRE:7O2C:FLWN:HE4Y:EZDF:ZGNF:OZRW:BUTZ:DBQK:MFR2
Docker Root Dir: /var/lib/docker
Debug Mode: false
Experimental: false
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false
OS: Ubuntu 22.04.4 LTS x86_64
Kernel: 5.15.0-107-generic
Uptime: 1 day, 23 hours, 12 mins
Packages: 847 (dpkg), 4 (snap)
Shell: fish 3.7.1
Resolution: 1024x768
Terminal: /dev/pts/0
CPU: Intel Xeon Silver 4316 (80) @ 3.400GHz
GPU: 03:00.0 Matrox Electronics Systems Ltd. Integrated
Memory: 24497MiB / 63830MiB
Anything else?
No response
Are you willing to submit PR?
- Yes I am willing to submit a PR!
Code of Conduct
- I agree to follow this project’s Code of Conduct
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 2
- Comments: 89 (41 by maintainers)
Commits related to this issue
- Swallow exception when mini-scheduling raises an exception When mini-scheduler raises an exception, it has a bit weird side effect - the task succeeds but it is seen as failed and scheduler gets conf... — committed to potiuk/airflow by potiuk 2 years ago
- Swallow exception when mini-scheduling raises an exception (#41260) When mini-scheduler raises an exception, it has a bit weird side effect - the task succeeds but it is seen as failed and scheduler... — committed to jscheffl/airflow by potiuk 2 years ago
Following… and adding some spice.
We have just upgraded to Airflow 2.9.2 and also have the (same) issue. Yet we have seen the problem in Airflow 2.8 (in our case the celery task airflow.exceptions.AirflowException: Celery command failed on host: slautop02 with celery_task_id 5d7f577d-3e89-4867-8481-24df778346ae (PID: 815333, Return Code: 256) but the Airflow tasks did not fail.
After reading this issue I also caugth this on shceduler logs: [2024-06-20T17:45:58.167+0100] {processor.py:161} INFO - Started process (PID=830424) to work on /home/ttauto/airflow/dags/ITSM_DAILY_INFORM_CLOSE_TASKS.py [2024-06-20T17:45:58.169+0100] {processor.py:830} INFO - Processing file /home/ttauto/airflow/dags/ITSM_DAILY_INFORM_CLOSE_TASKS.py for tasks to queue [2024-06-20T17:45:58.170+0100] {logging_mixin.py:188} INFO - [2024-06-20T17:45:58.170+0100] {dagbag.py:545} INFO - Filling up the DagBag from /home/ttauto/airflow/dags/ITSM_DAILY_INFORM_CLOSE_TASKS.py [2024-06-20T17:46:28.174+0100] {logging_mixin.py:188} INFO - [2024-06-20T17:46:28.173+0100] {timeout.py:68} ERROR - Process timed out, PID: 830424
Despite that these timeouts apear on several dags, we see no errors on the airflow ui neither on the airflow tasks We also cannot match the Pid in this logs with the pid mentioned on the celery tasks (pid XXX return code 256)
We are experiencing Celery tasks failures with the following stack trace: Traceback (most recent call last): File “/opt/tkapp/env_airflow/lib64/python3.9/site-packages/celery/app/trace.py”, line 453, in trace_task R = retval = fun(*args, **kwargs) File “/opt/tkapp/env_airflow/lib64/python3.9/site-packages/celery/app/trace.py”, line 736, in protected_call return self.run(*args, **kwargs) File “/opt/tkapp/env_airflow/lib64/python3.9/site-packages/airflow/providers/celery/executors/celery_executor_utils.py”, line 136, in execute_command _execute_in_fork(command_to_exec, celery_task_id) File “/opt/tkapp/env_airflow/lib64/python3.9/site-packages/airflow/providers/celery/executors/celery_executor_utils.py”, line 151, in _execute_in_fork raise AirflowException(msg) airflow.exceptions.AirflowException: Celery command failed on host: slautop02 with celery_task_id 5d7f577d-3e89-4867-8481-24df778346ae (PID: 815333, Return Code: 256)
Most of the times, this does not raise any issues and the dags tasks complete successfully without problems, even if the CELERY task is marked as failed, the airflow tasks completes successefully. Today we had a dag failure on the very first task ( an emptyoperator ) wit the exact same problem in the celery task. So the problem is now a real issue for us.
*** Found local files: *** * /opt/tkapp/airflow/logs/dag_id=CSDISPATCHER_SIMPLES/run_id=scheduled__2024-06-20T16:34:00+00:00/task_id=Start/attempt=1.log.SchedulerJob.log [2024-06-20, 17:39:30 WEST] {scheduler_job_runner.py:843} ERROR - Executor reports task instance <TaskInstance: CSDISPATCHER_SIMPLES.Start scheduled__2024-06-20T16:34:00+00:00 [queued]> finished (failed) although the task says it’s queued. (Info: None) Was the task killed externally? [2024-06-20, 17:50:47 WEST] {event_scheduler.py:40} WARNING - Marking task instance <TaskInstance: CSDISPATCHER_SIMPLES.Start scheduled__2024-06-20T16:34:00+00:00 [queued]> stuck in queued as failed. If the task instance has available retries, it will be retried. [2024-06-20, 17:50:48 WEST] {scheduler_job_runner.py:843} ERROR - Executor reports task instance <TaskInstance: CSDISPATCHER_SIMPLES.Start scheduled__2024-06-20T16:34:00+00:00 [queued]> finished (failed) although the task says it’s queued. (Info: None) Was the task killed externally?
We have investigated the (Return Code: 256) but without success, the “best” reason would be memory contention on the server but we also do not observe that.
Our server status, no exhaustion of resources.
version in use: apache-airflow==2.9.2 apache-airflow-providers-celery==3.7.2 apache-airflow-providers-common-io==1.3.2 apache-airflow-providers-common-sql==1.14.0 apache-airflow-providers-fab==1.1.1 apache-airflow-providers-ftp==3.9.1 apache-airflow-providers-hashicorp==3.7.1 apache-airflow-providers-http==4.11.1 apache-airflow-providers-imap==3.6.1 apache-airflow-providers-postgres==5.11.1 apache-airflow-providers-sftp==4.10.1 apache-airflow-providers-smtp==1.7.1 apache-airflow-providers-sqlite==3.8.1 apache-airflow-providers-ssh==3.11.1
We have just changed the AIRFLOW__CORE__EXECUTE_TASKS_NEW_PYTHON_INTERPRETER=True to try to get some more info.
OK. I think we are getting closer to the root cause thanks to that stacktrace. No airlfow picking is involved here (pickling is done internally by deepcopy).
What happens there:
I think a good solution would be @ashb @ephraimbuddy - following what you’ve done in https://github.com/apache/airflow/pull/27506 - to just skip mini-scheduler when something like that happens. In this case that would mean exiting mini-scheduler without raising any error if anything wrong happens during partial_subset.
WDYT @ashb @ephraimbuddy ?
Yes, And as I mentioned before with “survivorship bias” you think that it affects everyone but it’s not the case (otherwise we would be flooded with people stating it and it would show up in our tests and some of the service companies - Astronomer for one who runs latest version would also experienced it.
So the best what you can do is to provide some guesses, results of digging that will narrow down the problem - ideally possibly maybe bisecting things and disabling it - for example if someone (one of the teams here) experiences this problem on a staging system, turning on and off and modifying selected parameters one-by-one to see what can fix it is is a great engineering practice. I use it daily to narrow down and find out what the problem is by trying out and guessing - for Airflow CI.
And you can only, and exclusively use that techique when you have somewhat reproducible issue. Which narrows down the list of poeple who can actually do such check to those who experience it (or when we have eeasily reproducible case anyone can do it). If you don’t experience the problem, there is very little chance that you can guess what configuration or DAG might cause it. Especially when you have no access to the DAG and the environment where Airflow is run. On the other hand, when you DO experience it and DO have DAG access and CAN change and play with the configuration (for example on staging system) and DO have somewhat reproducible case, then yes - you can do bisecting and testing results of individual configuration changes.
And this is all we are asking here for: if any of people experiencing it and having somewhat reproducible case and be able to change various configuration parameters (by looking at the discussion above you will find a few of hypotheses) and creatively dig and find correlation and maybe try even different hypothesis - this might ACTUALLY help with diagnosis.
Yes. It will require time and dedication and focused effort from someone. And this the smallest thing the community can ask our users to contribute back as a sign of gratitude and
thank youfor the free software the community releases for free, I think that’s generally a small price to pay for all the cost saved (tens of thousands of dollars a month sometimes) for similar commercial solutions.Yeah - but one less is good 😃
This is quite the thread…
We really only see the
Airflow Task Timeout Error’s en masse in our biggest/busiest cluster, and I’m with @potiuk in that I’m not convinced its entirely Airflow core related. But I also think better tracing in celery would help a lot of us diagnose and mitigate issues.And my recent experience backs this up. We run on EKS, CeleryKubernetesExecutor, with AWS managed Redis backend. About 2 months ago the “Task Timeout Error” messages had finally ramped up to a level where someone thought it was worth me investigating rather than just retrying their dags. The first thing I noticed was an increase in logs like this:
After quite a bit of digging, I found that our celery workers started hitting the AWS EC2 limit of 1024 Packets Per Second Per ENI for DNS queries(we were running 3 kube-dns pods). However, it wasn’t immediately apparent DNS queries(even cluster local dns queries) were failing on the workers. Random celery tasks were just timing out for no apparent reason. (If you need to check if DNS is your problem, go here: https://repost.aws/knowledge-center/vpc-find-cause-of-failed-dns-queries)
TL;DR I switched us over to
NodeLocalDNSand these errors have gone way way down, but alas, it never completely eliminated them. Maybe Airflow has childhood trauma…Anyway, its that right there that tells me
Airflow Task Timeout Error’s could be caused by a long list of different things, but its a lack of good error logs and tracing that prevent us from knowing the true cause.On that note, I look forward to the integration of open-telemetry tracing in a future version of Airflow.
Yes. The thing is “whatever makes it possible to reproduce the issue”. If the maintainers are not able to reproduce the issue reliable, they can only make guesses, and even worse, even if they will come up with some hypothesis, and implement a supposed fix, they are not able to confirm or even confidently say that it fixes the issue. Having a minimal reproduction scenario is an absolute key to diagnose and fix the issue. It’s just a fact of “life” - fixing a problem at some remote, inaccessible installation that you are not able to dig deeper and look around (and nobody pays for time spent on it) is all about that. “Having reproducible scenario” increases chances of fixing the problem by at least few orders of magnitude. That’s simply how it works.
No - nothing specific comes to my mind - the problem with such issues is that if we knew what exactly to look at, then we would know what the cause of the issue is - which we don’t - and try to get enough of signals to be able to deduce it. Like with everything in complex systems there are no easy recipes to follow for diagnosing “rare” issues that are unexpected (the sheer fact of it that they are unexpected makes them difficult to diagnose, because you have no idea what to look at and you need to look at the “whole” system and try to spot anomalies.
However, soon (likely) in 2.10.0 there will be open-telemetry tracing integrated into Airflow’s observability, and this one will give much more detailed information on what’s going on with each task and I’d strongly recoommend to integrate it into your observability stack - especially that a number of tools that will use it will have an option to export such tracing and make it available to someone else than those who manager to be able to dig deeper. Until then we can mostly say “dig deeper”.
There is a monthly town hall tomorrow https://www.linkedin.com/feed/update/urn:li:activity:7216205556301090817 where @howardyoo is going to talk about it.
I did few tests with new version 2.9.2 and have the following details with the log
Configuration
I am running multiple instances of a dag with dynamic task mapping that expands into hundreds of tasks. The log shows that task gets scheduled and queued (at 2024-07-05T00:01:59.683) but does not get executed within task queued timeout period resulting into the reported error (at 2024-07-05T01:02:09.431)
I believe increasing AIRFLOW__SCHEDULER__TASK_QUEUED_TIMEOUT value might fix the issue. However, the root cause is still unknown, why did worker not process the task for an entire hour? Interesting observation is the failed task with this error is from the first instance of the DAG e.g. If I have 8 instances of the dag running, the error shows up in the 1st instance. Which indicates that tasks from all the instances are running and processed but somehow-sometime certain (not all) task from the 1st instance never gets executed. It may have to do with the overall throughput so tasks never stay in the queue for that long and I am not sure yet how to increase it. I have enough CPU and memory for the worker replicas as well as scheduler. Any ideas?
Sometimes similar issues are not the same issues, and upgrading to latest version of Airflow and checking there saves a lot of effort to voluntary people who want to help find issues, if the issue has been solved already, so this is the least effort you can do to help with it.
Not mentioning that lates versions (including 2.9.2) has latest fixes (including security fixes) - so well. it’s in the best interest of yours to upgrade
Sure, I can upgrade and check. I believe others here already tested on 2.9.2 reporting the same issue
@vizeit and anyone looking here and tempted to report “I have the same issue”. PLEASE before doing it upgrade to 2.9.2 and latest celery provider. And when you do, report it here whether things are fixed, and if not, add logs from the celery executor.
If you actually look at the discussion - some of related issues were fixed in 2.9.2 and Celery logging has been improved in latest provider to add more information. So the best thing you can do - is not really post “i have the same issue” but upgrade and let us know if it helped, and second best thing is to upgrade celery provider and post relevant logs.
Just posting “I have the same issue in 2.9.1” is not moving a needle when it comes to investigating and fixing such problem.
Hello everyone,
I’m currently investigating this issue, but I haven’t been able to replicate it yet. Could you please try setting
AIRFLOW__CORE__EXECUTE_TASKS_NEW_PYTHON_INTERPRETER=True[1] to see if we can generate more error logs? It seems that_execute_in_subprocessgenerates more error logs compared to_execute_in_fork, which might provide us with some additional clues.https://github.com/apache/airflow/blob/2d53c1089f78d8d1416f51af60e1e0354781c661/airflow/providers/celery/executors/celery_executor_utils.py#L187-L188
[1] https://airflow.apache.org/docs/apache-airflow/stable/configurations-ref.html#execute-tasks-new-python-interpreter
I was working on the issue with @seanmuth and increasing parsing time solved the issue. It does not fix the root cause, but as a workaround it can save your night…
AIRFLOW__CORE__DAGBAG_IMPORT_TIMEOUT = 120@RNHTTR there’s nothing stating “stuck in queued” on scheduler logs.