Graceful Reload vs Immediate Restart: Choosing a Safe Recovery Path for Failed uwsgi Upgrades
0 reputation · 28 Mar 2024, 19:53 UTC
0 reputation · 28 Mar 2024, 19:53 UTC
When upgrading uwsgi, administrators must decide between a graceful reload (SIGHUP) that preserves existing connections and an immediate restart (SIGTERM) that guarantees a clean state. The choice hinges on the risk of configuration errors and the tolerance for brief downtime.
Although the '--reload-on-failure' flag can revert to a previous configuration after a failed reload, its behavior varies across releases and may not cover all error scenarios. Additionally, graceful reloads can leave orphaned sockets if the new config changes socket paths, leading to race conditions during recovery.
31775 reputation · 28 Mar 2024, 20:22 UTC
When a uWSGI upgrade fails, the safest recovery path is usually an immediate restart (SIGTERM then start the last known‑good binary) unless you can confirm that the failure occurred *before* any new workers were spawned and that the master process detected the error and rolled back via --reload-on-failure. In that narrow case a graceful reload (SIGHUP) may be sufficient.
--reload-on-failure flag tells the master to revert to the previous binary/config if the reload handshake fails *before* the new workers accept connections.The master can only roll back when it detects a failure *during* the reload handshake: binary load error, config parse error, or worker init failure that causes the new workers to exit before they call accept(). If the failure happens after workers have started accepting requests (e.g., a runtime error in your application), the master treats the reload as successful and will not revert.
--reload-on-failure enabled, you can safely send SIGHUP; the master will have already rolled back.ps -fu www-data | grep uwsgi), then start the last known‑good binary.curl http://localhost:9191/stats) or uwsgitop: worker count should match the expected number, error rates (5xx) should drop to baseline, and response times should stabilize within a few seconds.Confirm whether the reload failure occurred *before* any new workers began accepting connections (i.e., during binary load/config parsing). If you can verify this, a graceful reload with --reload-on-failure may be sufficient; otherwise, proceed with an immediate restart.
Use comments to ask for clarification. Post a solution as an answer.
4,070 reputation · 29 Mar 2024, 01:22 UTC
One wrinkle the existing answer doesn't cover: --reload-on-failure only works when the master can observe the failure during the reload handshake. If you run with lazy-apps (or lazy), application loading is deferred into each worker after fork, so import errors and app-level exceptions surface after the master has already declared the reload successful. In that mode the rollback trigger often never fires — you get a "successful" reload whose workers crash on first request.
Verify on your exact version (uwsgi --version) in staging: inject a failing import, send SIGHUP, and watch whether worker PIDs return to the prior config. Behavior here has shifted across releases, so don't extrapolate from 2.0.x-era documentation.