Repository navigation
Description
Under which category would you file this issue?
Airflow Core
Apache Airflow version
3.2.2
What happened and how to reproduce it?
The scheduler memory grows until the process is OOMKilled and restarted. I attach a
Grafana graph with the growth over time.
We profiled the scheduler with memray, following the Airflow memory profiling guide.
The part that keeps growing is the DBDagBag cache of deserialized DAGs, which in the
scheduler is a plain dict with no eviction. Two memray snapshots from one run, with the memory retained under
get_dag_for_run / _get_dag:
| Snapshot | Peak heap | _get_dag (DBDagBag cache) |
|---|---|---|
| snapshot 1 | 1.38 GB | 464.9 MB |
| snapshot 2 | 2.18 GB | 669.5 MB |
The snapshots also show another large part, the task instances loaded during each scheduling
pass. That one seems normal.
The cause seems to be in SchedulerJobRunner.__init__:
self.scheduler_dag_bag = DBDagBag(load_op_links=False). With no cache_size, DBDagBag._dags
has no size or TTL limit, so it keeps one deserialized DAG per dag_version_id and does not
drop old versions. The bag lives for the whole scheduler process, which by default runs
indefinitely ([scheduler] num_runs = -1). As the number of DAG versions grows over time, this
becomes unbounded.
To reproduce: DAGs that keep producing new versions over time, a standalone dag-processor, and
a scheduler that runs for a long time. Watch len(scheduler_dag_bag._dags) and the process
resident memory (RSS). Both grow continuously and only go down after a restart.
What you think should happen instead?
The scheduler DBDagBag should use a bounded LRU+TTL cache, like the API server since #60804
(that PR limited the change to the API server only). Two settings, [scheduler] dag_cache_size
and dag_cache_ttl, like the [api] ones, would keep it bounded, with a size for the active
set of DAG versions and a TTL to drop the old ones. A value of 0 keeps today's unbounded
behavior.
Operating System
No response
Deployment
Official Apache Airflow Helm Chart
Apache Airflow Provider(s)
No response
Versions of Apache Airflow Providers
No response
Official Helm Chart version
1.21.0
Kubernetes Version
No response
Helm Chart configuration
No response
Docker Image customizations
No response
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
Activity
hiSandog commentedon Jun 29, 2026
The memray trace pointing at
_get_daggrowing 465→670MB lines up with the scheduler'sDBDagBaghaving no bound — unlike the API server, which got adag_cache_size/dag_cache_ttlknob in #60804. Mirroring that same config into[scheduler](and respecting it in theSchedulerJobRunnerDBDagBag(load_op_links=False)path) would cap the growth directly. Worth notingnum_runs=-1makes the scheduler run indefinitely, so without a TTL the cache only ever grows across the process lifetime. The API-server fix is a good template here since the access pattern is similar.VPatel5 commentedon Jul 8, 2026
I'm also facing this memory leak on the scheduler with 3.2.2 (Helm version 1.22.0)
Since the fix in #69007 is still in review and targeted at 3.3.1, is there a recommended workaround for the current version?
lohyenshen commentedon Jul 14, 2026
we are facing the same issue too, scheduler memory keeps growing
Helm version = 1.22.0
airflow version = 3.2.2
executor = CeleryExecutor
apache-airflow-providers-celery = 3.22.0
celery = 5.6.3
Bound the scheduler's deserialized Dag cache (apache#71704)
[v3-3-test] Bound the scheduler's deserialized Dag cache (#71704) (#7…
[v3-3-test] Bound the scheduler's deserialized Dag cache (#71704) (#7…