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 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/deployment.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ Options:
--timeout-graceful-shutdown INTEGER
Maximum number of seconds to wait for
graceful shutdown.
--timeout-worker-is-alive FLOAT
Maximum number of seconds to wait for
judging if a worker process is alive.
--ssl-keyfile TEXT SSL key file
--ssl-certfile TEXT SSL certificate file
--ssl-keyfile-password TEXT SSL keyfile password
Expand Down
3 changes: 3 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,9 @@ Options:
--timeout-graceful-shutdown INTEGER
Maximum number of seconds to wait for
graceful shutdown.
--timeout-worker-is-alive FLOAT
Maximum number of seconds to wait for
judging if a worker process is alive.
--ssl-keyfile TEXT SSL key file
--ssl-certfile TEXT SSL certificate file
--ssl-keyfile-password TEXT SSL keyfile password
Expand Down
2 changes: 2 additions & 0 deletions uvicorn/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ def __init__(
timeout_keep_alive: int = 5,
timeout_notify: int = 30,
timeout_graceful_shutdown: int | None = None,
timeout_worker_is_alive: float = 5,
callback_notify: Callable[..., Awaitable[None]] | None = None,
ssl_keyfile: str | os.PathLike[str] | None = None,
ssl_certfile: str | os.PathLike[str] | None = None,
Expand Down Expand Up @@ -256,6 +257,7 @@ def __init__(
self.timeout_keep_alive = timeout_keep_alive
self.timeout_notify = timeout_notify
self.timeout_graceful_shutdown = timeout_graceful_shutdown
self.timeout_worker_is_alive = timeout_worker_is_alive
self.callback_notify = callback_notify
self.ssl_keyfile = ssl_keyfile
self.ssl_certfile = ssl_certfile
Expand Down
10 changes: 10 additions & 0 deletions uvicorn/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,12 @@ def print_version(ctx: click.Context, param: click.Parameter, value: bool) -> No
default=None,
help="Maximum number of seconds to wait for graceful shutdown.",
)
@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

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.

Well... Those with heavy loads will have to change this. Which is a bothersome for them.

help="Maximum number of seconds to wait for judging if a worker process is alive.",
)
@click.option("--ssl-keyfile", type=str, default=None, help="SSL key file", show_default=True)
@click.option(
"--ssl-certfile",
Expand Down Expand Up @@ -396,6 +402,7 @@ def main(
limit_max_requests: int,
timeout_keep_alive: int,
timeout_graceful_shutdown: int | None,
timeout_worker_is_alive: float,
ssl_keyfile: str,
ssl_certfile: str,
ssl_keyfile_password: str,
Expand Down Expand Up @@ -445,6 +452,7 @@ def main(
limit_max_requests=limit_max_requests,
timeout_keep_alive=timeout_keep_alive,
timeout_graceful_shutdown=timeout_graceful_shutdown,
timeout_worker_is_alive=timeout_worker_is_alive,
ssl_keyfile=ssl_keyfile,
ssl_certfile=ssl_certfile,
ssl_keyfile_password=ssl_keyfile_password,
Expand Down Expand Up @@ -497,6 +505,7 @@ def run(
limit_max_requests: int | None = None,
timeout_keep_alive: int = 5,
timeout_graceful_shutdown: int | None = None,
timeout_worker_is_alive: float = 5,
ssl_keyfile: str | os.PathLike[str] | None = None,
ssl_certfile: str | os.PathLike[str] | None = None,
ssl_keyfile_password: str | None = None,
Expand Down Expand Up @@ -549,6 +558,7 @@ def run(
limit_max_requests=limit_max_requests,
timeout_keep_alive=timeout_keep_alive,
timeout_graceful_shutdown=timeout_graceful_shutdown,
timeout_worker_is_alive=timeout_worker_is_alive,
ssl_keyfile=ssl_keyfile,
ssl_certfile=ssl_certfile,
ssl_keyfile_password=ssl_keyfile_password,
Expand Down
2 changes: 1 addition & 1 deletion uvicorn/supervisors/multiprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def keep_subprocess_alive(self) -> None:
return # parent process is exiting, no need to keep subprocess alive

for idx, process in enumerate(self.processes):
if process.is_alive():
if process.is_alive(timeout=self.config.timeout_worker_is_alive):
continue

process.kill() # process is hung, kill it
Expand Down
Loading