Skip to content

Scheduler DBDagBag cache is never evicted and grows unbounded #69001

Description

@aeroyorch

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.

Image

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

Activity

  1. added
    kind:bug
    needs-triage
    on Jun 25, 2026
  2. removed
    needs-triage
    on Jun 26, 2026
  3. added this to the Airflow 3.3.1 milestone on Jun 26, 2026
  4. hiSandog commented on Jun 29, 2026

    @hiSandog

    The memray trace pointing at _get_dag growing 465→670MB lines up with the scheduler's DBDagBag having no bound — unlike the API server, which got a dag_cache_size/dag_cache_ttl knob in #60804. Mirroring that same config into [scheduler] (and respecting it in the SchedulerJobRunner DBDagBag(load_op_links=False) path) would cap the growth directly. Worth noting num_runs=-1 makes 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.

  5. VPatel5 commented on Jul 8, 2026

    @VPatel5

    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?

  6. lohyenshen commented on Jul 14, 2026

    @lohyenshen

    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

  7. added a commit that references this issue on Aug 19, 2026
    29dd99d
  8. added a commit that references this issue on Aug 19, 2026
    b326364
  9. added a commit that references this issue on Sep 7, 2026
    310b69f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:corearea:schedulerkind:bug

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions