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

add timeout_worker_is_alive as an option for main.run. #2397

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

socrateslee
Copy link

@socrateslee socrateslee commented Jul 25, 2024

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 #2396 , https://stackoverflow.com/questions/78680384/during-uvicorn-startup-child-process-dies-in-kubernetes-cluster may be caused by the case.

Checklist

  • 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.
  • I've updated the documentation accordingly.

The option let user set the timeout for judging if a process is dead in multiprocessing mode(i.e., workers > 1).
@Kludex Kludex requested a review from abersheeran July 31, 2024 21:17
@abersheeran
Copy link
Member

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

@socrateslee socrateslee force-pushed the feature/timeout_worker_is_alive branch from ea7ecc6 to f1873bc Compare August 1, 2024 07:20
@socrateslee
Copy link
Author

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

checks passed, please go ahead

@Kludex
Copy link
Member

Kludex commented Sep 16, 2024

Defaulting to a low number doesn't seem right.

@xconverge
Copy link

xconverge commented Oct 10, 2024

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

@lightbeem3296
Copy link

lightbeem3296 commented Oct 23, 2024

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.
🙏🙏🙏

@lightbeem3296
Copy link

lightbeem3296 commented Oct 23, 2024

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.

Copy link
Member

@abersheeran abersheeran left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job.

@encode encode locked as spam and limited conversation to collaborators Oct 23, 2024
@click.option(
"--timeout-worker-is-alive",
type=float,
default=5,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this is wanted as default value?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I've mentioned before: #2397 (comment)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it's a good default value for most programs. Only those with heavy loads require larger values.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additionally, the default timeout for a single request in httpx is also 5 seconds.

Copy link

@lightbeem3296 lightbeem3296 Oct 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Failed some checks. Can I fix it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, please fix it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's an unrelated issue on the pipeline.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @Kludex ,
I think, it's not only current branch issue.
Your master branch doesn't pass scripts/test too.
Could you please checkout?
image

@encode encode unlocked this conversation Oct 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hold Don't merge yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants