Skip to content

Celery integration leaking file descriptors #5422

Closed

Description

@pdewacht

How do you use Sentry?

Sentry Saas (sentry.io)

Version

2.51.0

Steps to Reproduce

After upgrading to Python 3.14, our Celery tasks started failing with 'too many open files' errors. We found that

  • Sentry's Celery integration leaks a file descriptor for every task executed
  • Python 3.14's new GC is less aggressive and leaked file descriptors can hang around for much longer

The relevant code is:

with capture_internal_exceptions():
span.set_data(
SPANDATA.MESSAGING_SYSTEM,
task.app.connection().transport.driver_type,
)

Accessing the transport property will create a new redis connection. (We use a redis broker but I assume the behavior is the same for other transport types.) This connection is never closed so it's left to the GC to clean up.

To see this in action, take the "add" example from https://docs.sentry.io/platforms/python/integrations/celery/, configure a redis broker and change the main function to queue many tasks:

def main():
    for _ in range(1000):
        add.delay(4, 4)

Use Python 3.14, celery[redis]==5.6.2, sentry-sdk==2.51.0. Then check /proc/(worker pid)/fd/.

Expected Result

The Celery worker has few open files.

Actual Result

The Celery worker has hundreds of anon_inode:[eventpoll] files.

Activity

  1. linear commented on Feb 4, 2026

    @linear
  2. moved this to Waiting for: Product Owner in GitHub Issues with 👀 3on Feb 4, 2026
  3. alexander-alderman-webb commented on Feb 4, 2026

    @alexander-alderman-webb
    Collaborator

    Thanks for the well-written report @pdewacht. We'll resolve the leak and keep you updated.

  4. moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 3on Feb 4, 2026
  5. self-assigned this
    on Feb 5, 2026
  6. sentrivana commented on Feb 6, 2026

    @sentrivana
    Collaborator

    So I looked into this and while I can't reproduce the leak (I'm on MacOS so that might be part of the reason), it's clear that we should be closing the connection if we open one. There's a fix for that here.

    On the other hand, I'm not happy with us opening connections, especially just for the purpose of determining the driver type. Opened #5428 to see whether this can be improved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions