Skip to content

Commit

Permalink
Exit with status 3 when worker starts failed (#1077)
Browse files Browse the repository at this point in the history
* fix: exit with status 3 when worker starts failed to aviod infinite start/stop cycles

* docs: fixes spelling error

* style: lint the code

* fix: replace magic exit code

Co-authored-by: fanchunke <fanchunke@laiye.com>
  • Loading branch information
fanchunke and fanchunke authored Jun 22, 2021
1 parent b5af104 commit e885bbd
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions uvicorn/workers.py
Original file line number Diff line number Diff line change
@@ -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
if not server.started:
sys.exit(Arbiter.WORKER_BOOT_ERROR)

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

0 comments on commit e885bbd

Please sign in to comment.