Skip to content

Commit 7ea7e2f

Browse files
committed
fix: address code review — spawn timeout and CLI timeout consistency
- Replace hardcoded 5s spawn timeout with _SPAWN_TIMEOUT (15s), capped at the caller's timeout value for short timeouts - CLI commands now use _INSTALL_TIMEOUT from service module instead of hardcoded 600
1 parent 94aad96 commit 7ea7e2f

2 files changed

Lines changed: 6 additions & 3 deletions

File tree

Server/src/cli/commands/unity_hub.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
from cli.utils.output import print_info, print_success
99
from services.unity_hub import (
10+
_INSTALL_TIMEOUT,
1011
detect_hub_path,
1112
parse_available_releases,
1213
parse_installed_editors,
@@ -103,7 +104,7 @@ def install_path(new_path: str | None) -> None:
103104
def install(version: str) -> None:
104105
"""Download and install a Unity Editor version via Unity Hub."""
105106
click.confirm(f"Install Unity Editor {version}?", abort=True)
106-
result = _run_async(run_hub_command(["install", "--version", version], timeout=600))
107+
result = _run_async(run_hub_command(["install", "--version", version], timeout=_INSTALL_TIMEOUT))
107108
if result["success"]:
108109
print_success(f"Unity Editor {version} installation started.")
109110
print_info("Unity Hub may continue the install in the background.")
@@ -121,7 +122,7 @@ def install_modules(version: str, modules: tuple[str, ...]) -> None:
121122
args = ["install-modules", "--version", version]
122123
for mod in module_list:
123124
args.extend(["--module", mod])
124-
result = _run_async(run_hub_command(args, timeout=600))
125+
result = _run_async(run_hub_command(args, timeout=_INSTALL_TIMEOUT))
125126
if result["success"]:
126127
print_success(f"Module installation started for Unity {version}.")
127128
print_info("Unity Hub may continue the module install in the background.")

Server/src/services/unity_hub.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
_DEFAULT_TIMEOUT = 30
2020
_INSTALL_TIMEOUT = 600
21+
_SPAWN_TIMEOUT = 15
2122

2223

2324
def detect_hub_path() -> Optional[str]:
@@ -61,13 +62,14 @@ async def run_hub_command(
6162
cmd = [hub, "--", "--headless", *args]
6263

6364
try:
65+
spawn_timeout = min(_SPAWN_TIMEOUT, timeout)
6466
proc = await asyncio.wait_for(
6567
asyncio.create_subprocess_exec(
6668
*cmd,
6769
stdout=asyncio.subprocess.PIPE,
6870
stderr=asyncio.subprocess.PIPE,
6971
),
70-
timeout=5,
72+
timeout=spawn_timeout,
7173
)
7274
stdout_bytes, stderr_bytes = await asyncio.wait_for(
7375
proc.communicate(),

0 commit comments

Comments
 (0)