Skip to content

fix: release app configs held by Celery signal handlers #744

Closed

Description

@uniqueg

Problem

For apps with a database, foca.factories.celery_app connects handlers to Celery's worker_init and worker_process_init signals with weak=False, so that a worker reopens the MongoDB client around forks. Each handler refers to the app's MongoConfig, which holds the MongoDB client, so the signals keep every such configuration and client alive (but not the Flask app). Processes that create many apps, such as test suites or scripts that use Foca.use_config() or create_app() repeatedly, accumulate them.

The dispatch_uid of each handler is derived from id() of the configuration, which is only unique while the configuration is alive.

Proposed change

Keep the handlers from holding the configurations, e.g., one handler that is kept alive deliberately and reopens the clients of the configurations that are still alive (held by weak references), so that configurations and clients are released when their app is. Add a regression test that checks with gc and weakref that a configuration is collected, like the one of #735, and a release note under Fixes.

Activity

  1. added this to the v0.22.0 milestone on Nov 7, 2026
  2. added
    priority: low
    status: triage
    type: bug
    workload: hours
    status: in progress
    and removed
    status: triage
    on Nov 7, 2026
  3. removed
    status: in progress
    on Nov 9, 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

    Labels

    priority: lowtype: bugworkload: hours

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions