Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exit with status 3 when worker starts failed #1077

Merged
merged 4 commits into from Jun 22, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions uvicorn/workers.py
@@ -1,8 +1,10 @@
import asyncio
import logging
import signal
import sys
from typing import Any

from gunicorn.arbiter import Arbiter
from gunicorn.workers.base import Worker

from uvicorn.config import Config
Expand Down Expand Up @@ -75,6 +77,11 @@ def run(self) -> None:
server = Server(config=self.config)
loop = asyncio.get_event_loop()
loop.run_until_complete(server.serve(sockets=self.sockets))
# Exit with status 3 when worker starts failed, so Gunicorn
# can shut it down to avoid infinite start/stop cycles.
# See: https://github.com/encode/uvicorn/issues/1066
Kludex marked this conversation as resolved.
Show resolved Hide resolved
if not server.started:
sys.exit(Arbiter.WORKER_BOOT_ERROR)

async def callback_notify(self) -> None:
self.notify()
Expand Down