uvicorn icon indicating copy to clipboard operation
uvicorn copied to clipboard

add timeout_worker_is_alive as an option for main.run.

Open socrateslee opened this issue 1 year ago • 6 comments

Summary

The option lets users set the timeout for judging if a process is dead in multiprocessing mode(i.e., workers > 1). When the module calls uvicorn.run has some heavy load like importing a lot of modules, the is_alive check in supervisors.multiprocessing may be blocked. When this happens, the default 5 seconds timeout may cause the misjudgement of a process and kill it. Issues like https://github.com/encode/uvicorn/discussions/2396 , https://stackoverflow.com/questions/78680384/during-uvicorn-startup-child-process-dies-in-kubernetes-cluster may be caused by the case.

Checklist

  • [x] I understand that this PR may be closed in case there was no previous discussion. (This doesn't apply to typos!)
  • [ ] I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • [x] I've updated the documentation accordingly.

socrateslee avatar Jul 25 '24 15:07 socrateslee

This PR does fix some edge cases. Please fix the CI failures so we can merge it.

abersheeran avatar Aug 01 '24 01:08 abersheeran

This PR does fix some edge cases. Please fix the CI failures so we can merge it.

checks passed, please go ahead

socrateslee avatar Aug 05 '24 02:08 socrateslee

Defaulting to a low number doesn't seem right.

Kludex avatar Sep 16 '24 18:09 Kludex

Defaulting to a low number doesn't seem right.

It reads to me to be defaulting to the exact number that is already being used to preserve behavior I think?

https://github.com/encode/uvicorn/blob/master/uvicorn/supervisors/multiprocess.py#L65

xconverge avatar Oct 10 '24 20:10 xconverge

Hi @abersheeran, I urgently need this feature. During my project development, in case of multiple workers, child processes are dying every 5 seconds. I discovered that this PR resolves the issue. Please merge this PR as soon as possible. 🙏🙏🙏

alphadev3296 avatar Oct 23 '24 02:10 alphadev3296

I've tried almost Uvicorn alternatives including Gunicorn, Hypercorn, Daphne, Sanic, Tornado, Waitress. But I love Uvicorn most. Unfortunately, worker alive timeout is hardcoded. If only this is fixed, Uvicorn is almost PERFECT. Please merge this PR ASAP.

alphadev3296 avatar Oct 23 '24 13:10 alphadev3296

Any status update on this?

Thank you.

UDPSOCKET avatar Aug 13 '25 12:08 UDPSOCKET

We are using Airflow 3 and are noticing issues because of the currently hardcoded 5s, sometimes Airflows fails to start up because of it. This is currently mitigated by setting the workers to 1, but is not a good solution.

See: https://github.com/stackabletech/airflow-operator/issues/641

@Kludex can I ask you to have a look at this PR again, as the impact is quite high for Airflow users

stijndehaes avatar Sep 22 '25 08:09 stijndehaes

See: stackabletech/airflow-operator#641

We (@stackabletech) sponsored @Kludex to look at this and get it merged. Thank you for following up on it and getting it merged so fast. @stijndehaes we'll include it in our next version.

lfrancke avatar Sep 23 '25 13:09 lfrancke