Description
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