airflow: Airflow dag processor exits with too many open files after sometime

Apache Airflow version

3.0.0

If “Other Airflow 2 version” selected, which one?

No response

What happened?

Upgraded Airflow from 2.10 to 3.0.0 and DagProcessorJob getting failed after few hours. with below exception OSError: [Errno 24] Too many open files

[2025-04-25T21:30:41.765+0100] {dag_processor_job_runner.py:63} ERROR - Exception when executing DagProcessorJob
Traceback (most recent call last):
  File "/var/opt/rdos-airflow/venv/lib/python3.10/site-packages/airflow/jobs/dag_processor_job_runner.py", line 61, in _execute
    self.processor.run()
  File "/var/opt/rdos-airflow/venv/lib/python3.10/site-packages/airflow/dag_processing/manager.py", line 262, in run
    return self._run_parsing_loop()
  File "/var/opt/rdos-airflow/venv/lib/python3.10/site-packages/airflow/dag_processing/manager.py", line 347, in _run_parsing_loop
    self._start_new_processes()
  File "/var/opt/rdos-airflow/venv/lib/python3.10/site-packages/airflow/dag_processing/manager.py", line 894, in _start_new_processes
    processor = self._create_process(file)
  File "/var/opt/rdos-airflow/venv/lib/python3.10/site-packages/airflow/dag_processing/manager.py", line 876, in _create_process
    return DagFileProcessorProcess.start(
  File "/var/opt/rdos-airflow/venv/lib/python3.10/site-packages/airflow/dag_processing/processor.py", line 245, in start
    proc: Self = super().start(target=target, **kwargs)
  File "/var/opt/rdos-airflow/venv/lib/python3.10/site-packages/airflow/sdk/execution_time/supervisor.py", line 446, in start
    child_comms, read_msgs = mkpipe()
  File "/var/opt/rdos-airflow/venv/lib/python3.10/site-packages/airflow/sdk/execution_time/supervisor.py", line 177, in mkpipe
    rsock, wsock = socketpair()
  File "/var/opt/icetools/python/ICEpythonvenv310/python-3.10.1/lib/python3.10/socket.py", line 607, in socketpair
    a, b = _socket.socketpair(family, type, proto)
OSError: [Errno 24] Too many open files

What you think should happen instead?

No response

How to reproduce

nohup airflow dag-processor

DAG Processor Config

export AIRFLOW__DAG_PROCESSOR__BUNDLE_REFRESH_CHECK_INTERVAL=10
export AIRFLOW__DAG_PROCESSOR__MIN_FILE_PROCESS_INTERVAL=120
export AIRFLOW__DAG_PROCESSOR__PARSING_PROCESSES=1
export AIRFLOW__DAG_PROCESSOR__REFRESH_INTERVAL=900

Operating System

RHEL 8.8

Versions of Apache Airflow Providers

No response

Deployment

Virtualenv installation

Deployment details

No response

Anything else?

This problem occurs always for every few hours once. Number of DAGs less than 10.

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Code of Conduct

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 55 (48 by maintainers)

Commits related to this issue

Most upvoted comments

comrades, i’m happy to report that adding @functools.cache on top of def in_process_api_server() is able to solve both this issue and the memory issue! 🎉

Image

Thanks @kaxil and @tirkarthi for bringing this to closure.

Thanks @kaxil for the PR. I guess there doesn’t seem to be issue with the task-sdk and triggerer. triggerer is long running with the client initiated only at startup. task-sdk has this per task instance execution but in case of production executors they will be in a different kubernetes pod or celery host to hit the limit. This can be revisited if there are reports in future of similar socket leak.

@tirkarthi 👍 gonna test it out today on top of airflow 3.0.1

my fellow detectives, l confirmed there was still a small memory leak somewhere

Image

the red oval was when i applied @kaxil fix https://github.com/apache/airflow/pull/50558

the good news is the open fds issue is completely solved by @kaxil fix https://github.com/apache/airflow/pull/50558 or @tirkarthi patch 🎉

and there is an important clue here: prior to the fix i had a unrelated typo in the code so the dag processor was failing at

...
File "/usr/local/airflow/.local/lib/python3.12/site-packages/airflow/dag_processing/manager.py", line 889, in _create_process
return DagFileProcessorProcess.start(
...

which means the memory leak occurs even BEFORE the core parts of dag processor (see the rising trend on the left of the red oval)

@kaxil yep gonna do it today

Thanks man, I appreciate all your help in investigating this

@kaxil yep gonna do it today

Good job @tirkarthi !

OK. I nthis case the problem (which we should see to) is triggered by bad using of f-strings. The way the method is used, f-string is evaluated while parsing the dag so - contrary to your expectations - the _get_credential_from_conn method is called every time the DAG is parsed. You should rather use jinja template for that and register your method to be called as custom macro - you can add such macros via “user_defined_macros” parameter of the DAG @dramis.

I thin the root cause @ashb @uranusjr is that “get_connection” run this way leaves some stream opened.

Another suggestion: Can anyone who experiences the growth of open files, can run (With root) lsof few times before the number is exceeded and dump it somewhere with information on timing and growth ? There are quite a few options that can be specified to lsof but seeing the “growth” - i…e. seeing what kind of open files are growing and seeing clearly that they are growing might help to narrow down the reason. And if we see the kinds of open files growing and possibly what is opening them, we can likely run a few more details lsof commands to get more details.