Fix FastAPI worker crash and improve container stability#17
Fix FastAPI worker crash and improve container stability#17
Conversation
This commit addresses the issue where worker processes would die upon startup in a containerized environment (e.g., Kubernetes). 1. Switched from Alpine-based to Debian-based slim Python image to improve compatibility with C extensions and provide a more stable runtime environment. 2. Refactored app/main.py to use FastAPI's lifespan event handler for initializing the MongoClient. This ensures each worker process creates its own connection pool after forking, preventing issues with shared file descriptors. 3. Added build-essential to the Dockerfile to ensure that dependencies can be compiled if necessary. Co-authored-by: nmagee <699798+nmagee@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
The FastAPI application was crashing when run with multiple workers in a containerized environment (Alpine Linux). This was primarily due to the MongoDB client being initialized at the module level (before process forking) and potential compatibility issues between Alpine's musl libc and Python C extensions.
I have:
python:3.11-slim.MongoClientinitialization into a FastAPIlifespanhandler to ensure it happens after process forking.build-essentialto the Docker build process for robust dependency installation.Verified that the application starts successfully with 4 workers and each worker correctly initializes its own MongoDB client.
PR created automatically by Jules for task 8611624801302620715 started by @nmagee