Skip to content

Zero-Downtime restart #2757

@yangbo1024

Description

@yangbo1024

Initial Checks

  • I confirm this was discussed, and the maintainers suggest I open an issue.
  • I'm aware that if I created this issue without a discussion, it may be closed without a response.

Discussion Link

No link.

Description

Hello. I’ve encountered two requirements for which I can’t seem to find a proper solution in Uvicorn for now:

  1. For a singleton service that must run with only 1 worker but requires a graceful restart. When sending a SIGHUP to Uvicorn, the process exits.
  2. For another service with 2 workers, when sending a SIGHUP to Uvicorn, the restart happens one by one—specifically, shutting down the old worker first before starting a new one.

I’m using Uvicorn directly without Gunicorn. Based on the information I’ve researched and my actual tests, Gunicorn’s connection handling mechanism, even with the reuse_port option, still has issues with uneven load distribution across multiple workers.

What I expect from Uvicorn is:
For the single-worker scenario, when the master process receives a SIGHUP, it should shut down the old worker and start a new one instead of exiting.
Regarding the worker startup order, I believe the correct approach should be to start the new worker first. This ensures the service doesn’t interrupt and prevents a sudden increase in load on the original worker.

I’m wondering if I’m using something incorrectly, or can uvicorn add the features? Thanks!

Example Code

Python, Uvicorn & OS Version

Python 3.12.3, Uvicorn 0.38.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions