uvicorn icon indicating copy to clipboard operation
uvicorn copied to clipboard

UvicornWorker: respect the gunicorn graceful shutdown timeout

Open BrendanGraham14 opened this issue 2 years ago • 4 comments

Summary

This change propagates Gunicorn's graceful_timeout parameter to Uvicorn's timeout_graceful_shutdown configuration when running Uvicorn as a Gunicorn worker process.

Checklist

  • [x] I understand that this PR may be closed in case there was no previous discussion. (This doesn't apply to typos!)
  • Not sure if a test is necessary here? In any case it looks like UvicornWorker doesn't have any tests currently.
  • [x] I've updated the documentation accordingly.

BrendanGraham14 avatar Sep 06 '23 05:09 BrendanGraham14

I don't think they are equivalent.

Kludex avatar Sep 06 '23 05:09 Kludex

@Kludex what's the difference?

Gunicorn: https://docs.gunicorn.org/en/stable/signals.html#master-process

TERM: Graceful shutdown. Waits for workers to finish their current requests up to the graceful_timeout.

graceful_timeout After receiving a restart signal, workers have this much time to finish serving requests. Workers still alive after the timeout (starting from the receipt of the restart signal) are force killed.

Uvicorn: https://www.uvicorn.org/settings/#timeouts

--timeout-graceful-shutdown - Maximum number of seconds to wait for graceful shutdown. After this timeout, the server will start terminating requests.

BrendanGraham14 avatar Sep 06 '23 06:09 BrendanGraham14

I think the details are on the PR that introduced it. But I think it's because the one from Uvicorn is related to the ASGI event (shutdown).

Kludex avatar Sep 06 '23 07:09 Kludex

Hm, but they both apply to the graceful termination of workers/tasks in the event of a signal to shutdown. Is there any reason to be concerned about making the Uvicorn worker aware of the graceful shutdown timeout?

BrendanGraham14 avatar Sep 07 '23 04:09 BrendanGraham14

We are deprecating the workers module within Uvicorn. PR welcome on https://github.com/Kludex/uvicorn-worker.

Kludex avatar Apr 13 '24 11:04 Kludex