Skip to content

EventDispatcher leaks memory via _outbound_buffer after broker reconnection (gevent pool) #10273

Closed

Description

@JaeHyuckSa

Checklist

  • I have verified that the issue exists against the main branch of Celery.
  • I have read the relevant section in the
    contribution guide
    on reporting bugs.
  • I have checked the issues list
    for similar or identical bug reports.
  • I have checked the pull requests list
    for existing proposed fixes.
  • I have checked the commit log
    to find out if the bug was already fixed in the main branch.
  • I have included all related issues and possible duplicate issues
    in this issue (If there are none, check this box anyway).

Mandatory Debugging Information

  • I have included the output of celery -A proj report in the issue.
    (if you are not able to do this, then at least specify the Celery
    version affected).
  • I have verified that the issue exists against the main branch of Celery.
  • I have included the contents of pip freeze in the issue.
  • I have included all the versions of all the external dependencies required
    to reproduce this bug.

Related Issues and Possible Duplicates

Related Issues

Possible Duplicates

  • None

Environment & Settings

Celery version: 5.6.3

celery report Output:

software -> celery:5.6.3 (dawn-chorus) kombu:5.6.2 py:3.14.0
            billiard:4.2.4 py-amqp:5.3.1
platform -> system:Linux arch:64bit, ELF
            kernel version:***
loader   -> celery.loaders.app.AppLoader
settings -> transport:amqps result:N/A

broker_url: amqps://***:***@***:5671/***
deprecated_settings: None

Steps to Reproduce

Required Dependencies

  • Minimal Python Version: 3.11
  • Minimal Celery Version: 5.4
  • Minimal Kombu Version: 5.6.2
  • Minimal Broker Version: RabbitMQ 3
  • Minimal Result Backend Version: N/A
  • Minimal OS and/or Kernel Version: N/A
  • Minimal Broker Client Version: amqp 5.3.1
  • Minimal Result Backend Client Version: N/A

Python Packages

pip freeze Output:

amqp==5.3.1
billiard==4.2.4
celery==5.6.3
click==8.3.2
click-didyoumean==0.3.1
click-plugins==1.1.1.2
click-repl==0.3.0
gevent==26.4.0
greenlet==3.4.0
kombu==5.6.2
packaging==26.1
prompt-toolkit==3.0.52
psutil==7.2.2
python-dateutil==2.9.0.post0
six==1.17.0
tzdata==2026.1
tzlocal==5.3.1
vine==5.1.0
wcwidth==0.6.0
zope-event==6.1
zope-interface==8.3

Other Dependencies

Details

Docker (for RabbitMQ container)

Minimally Reproducible Test Case

Details

https://github.com/JaeHyuckSa/celery-gevent-memory-leak-issue

uv sync
uv run python main.py

Expected Behavior

After broker reconnection, the old EventDispatcher should stop its heartbeat timer or guard against producer=None, so no objects accumulate in _outbound_buffer.

Actual Behavior

When the broker connection drops and reconnects, the old EventDispatcher's heartbeat timer keeps calling _publish() with producer=None.

https://github.com/celery/celery/blob/main/celery/events/dispatcher.py#L142-L160

try:
    producer.publish(...)
except Exception as exc:
    if not self.buffer_while_offline:
        raise
    self._outbound_buffer.append((event, routing_key, exc))

producer is None, so producer.publish() raises AttributeError. _publish() catches it and appends (event, routing_key, exc) to _outbound_buffer. The exception keeps traceback/frame references alive, so they never get GC'd. This repeats every ~2s.

Activity

  1. auvipy commented on Apr 21, 2026

    @auvipy
    Member

    are you up for fixing this?

  2. JaeHyuckSa commented on Apr 21, 2026

    @JaeHyuckSa
    ContributorAuthor

    Hello @auvipy, @Song-Junho97 is a colleague of mine working on the same project, and he has already looked into this issue in detail. He’s also interested in working on a fix, so we’re planning to take a look at it together.

  3. auvipy commented on Apr 21, 2026

    @auvipy
    Member

    Ok that would be great

  4. added this to the 5.7.0 milestone on Apr 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions