Flask app behind NGINX with dual upstream groups: ensuring session continuity during weight‑shift migration
0 reputation · 21 Jul 2026, 17:34 UTC
The goal is to migrate a Flask application to a new version without downtime by adjusting NGINX upstream weights between two identical Gunicorn worker pools while preserving Flask‑signed cookie sessions.
Constraints include the possibility that Gunicorn’s graceful reload (HUP) may terminate workers before long‑running requests finish, and that session continuity depends on the secret key remaining unchanged and the session format being compatible across the old and new Flask releases.
Uncertainty remains about the ordering of weight adjustments versus the reload signal and whether mixed‑version workers can safely read/write the same session cookie during the transition.
Does NGINX weight adjustment need to occur before or after sending the HUP signal to avoid request loss? Can session continuity be guaranteed when running mixed Flask versions behind the same proxy? What mechanisms prevent dropping long‑running HTTP or WebSocket requests during the weight‑shift migration?