"""Gunicorn configuration for the chore/reward Flask backend.

This file is automatically loaded by Gunicorn when it is started from the
backend directory.  It ensures each worker process creates its own MongoDB
client after forking, avoiding shared socket/file-descriptor issues.
"""


def post_fork(server, worker):
    """Reinitialize the MongoDB client in each worker process after forking."""
    try:
        from db.mongo_client import init_mongo_client
        init_mongo_client()
    except Exception:
        # If MongoDB is not configured (USE_MONGODB=false), there is no client
        # to initialize; ignore the error silently.
        pass
