I'd be happy to share publicly.
Deployment Info:
This application is basically a Service Oriented Architecture of multiple independent services deployed on 3 platforms with interconnected services: `Pyramid` Web Servers, `Celery` Task Mangers, and `Twisted` task runners. Both the `Pyramid` and `Celery` services fork (`Pyramid` is deployed via a `uWSGI` container on `nginx`, but the native `waitress` server forks); `Celery` forks as well. `SqlAlchemy` is used to talk to `Postgres`, and is fork-safe through calling `engine.dispose()` at a post-fork hooks (celery and waitress both have a hook). `Redis` is involved as well, and the python client auto-detects a fork (it compares PIDs since version 2.4.12).
There can be a couple of mongo clients/servers involved with a given application. The connection info and credentials are split between `.ini` files used by the application and python files managed by `blackbox` (
https://github.com/StackExchange/blackbox).
Pre-Fork connection:
Connections happen pre-fork for 2 general reasons:
1. Ensure the data service is running. I want to ensure a read/write as part of the initial startup against all the backing data stores. For development/testing, failing fast will streamline a resolution. For production, it's better to fail at this stage before registering that server behind a load balancer.
2. Pre-load data before a fork, both to optimize copy-on-write behavior and avoid a bottleneck of 12+ instances on each node querying the backend for 10MB of info simultaneously.
There were probably other concerns, these just popped to the top of my head.
Because of how the various frameworks handle configuration data, the info needed to create a new client may or may not be easy to access after a fork. In Pyramid's case, the information would be in the application registry, which is best accessed via an API object. There is a 'threadlocal' way to access this information (`get_current_registry`) but all the threadlocal functions are recommended against under production.
ANYWAYS, It took me longer to write a fix than to write this email - I just wrapped the mongo client in a container with the credentials.
If you have any questions on anything, be sure to cc me directly and I'll try to answer anything I can.