From 913bacdf31e1941d0a0eec87b5ebc8b1ade12a91 Mon Sep 17 00:00:00 2001 From: fanchunke Date: Sat, 12 Jun 2021 21:58:19 +0800 Subject: [PATCH 1/4] fix: exit with status 3 when worker starts failed to aviod infinite start/stop cycles --- uvicorn/workers.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/uvicorn/workers.py b/uvicorn/workers.py index 4ffe2ebd9..0680bf6f6 100644 --- a/uvicorn/workers.py +++ b/uvicorn/workers.py @@ -1,6 +1,7 @@ import asyncio import logging import signal +import sys from typing import Any from gunicorn.workers.base import Worker @@ -75,6 +76,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 aviod infinite start/stop cycles. + # See: https://github.com/encode/uvicorn/issues/1066 + if not server.started: + sys.exit(3) async def callback_notify(self) -> None: self.notify() From 31b2b72375553d2399bcdfb280015bad1a250d0b Mon Sep 17 00:00:00 2001 From: fanchunke Date: Sat, 12 Jun 2021 22:46:01 +0800 Subject: [PATCH 2/4] docs: fixes spelling error --- uvicorn/workers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/uvicorn/workers.py b/uvicorn/workers.py index 0680bf6f6..fb9b26d94 100644 --- a/uvicorn/workers.py +++ b/uvicorn/workers.py @@ -77,7 +77,7 @@ def run(self) -> None: 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 aviod infinite start/stop cycles. + # can shut it down to avoid infinite start/stop cycles. # See: https://github.com/encode/uvicorn/issues/1066 if not server.started: sys.exit(3) From fa73785cd91d9571c45fea913ecf38279e93ed88 Mon Sep 17 00:00:00 2001 From: fanchunke Date: Sun, 13 Jun 2021 22:21:09 +0800 Subject: [PATCH 3/4] style: lint the code --- uvicorn/workers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/uvicorn/workers.py b/uvicorn/workers.py index fb9b26d94..f4e8c79dc 100644 --- a/uvicorn/workers.py +++ b/uvicorn/workers.py @@ -76,7 +76,7 @@ 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 + # 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 if not server.started: From 5efe23b3fa01129bd4610be663b07d98dcf3dfc6 Mon Sep 17 00:00:00 2001 From: fanchunke Date: Wed, 23 Jun 2021 00:01:46 +0800 Subject: [PATCH 4/4] fix: replace magic exit code --- uvicorn/workers.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/uvicorn/workers.py b/uvicorn/workers.py index f4e8c79dc..f2dc0c5b7 100644 --- a/uvicorn/workers.py +++ b/uvicorn/workers.py @@ -4,6 +4,7 @@ import sys from typing import Any +from gunicorn.arbiter import Arbiter from gunicorn.workers.base import Worker from uvicorn.config import Config @@ -80,7 +81,7 @@ def run(self) -> None: # can shut it down to avoid infinite start/stop cycles. # See: https://github.com/encode/uvicorn/issues/1066 if not server.started: - sys.exit(3) + sys.exit(Arbiter.WORKER_BOOT_ERROR) async def callback_notify(self) -> None: self.notify()