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

Retry ray start if port is still occupied #1059

Merged
merged 1 commit into from
Jul 24, 2024
Merged
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
24 changes: 21 additions & 3 deletions runhouse/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,6 @@ def _start_server(
existing_ray_instance = check_for_existing_ray_instance()
if not existing_ray_instance or restart_ray:
cmds.append(RAY_KILL_CMD)
cmds.append("sleep 5")
cmds.append(RAY_START_CMD)

# Collect flags
Expand Down Expand Up @@ -662,8 +661,27 @@ def _start_server(
result = subprocess.run(cmd, shell=True, check=True)
else:
result = subprocess.run(shlex.split(cmd), text=True)
# We don't want to raise an error if the server kill fails, as it may simply not be running
if result.returncode != 0 and "pkill" not in cmd:

if result.returncode != 0:
# We don't want to raise an error if the server kill fails, as it may simply not be running
if "pkill" in cmd:
continue

# Retry ray start in case pkill process did not complete in time, up to 10s
if cmd == RAY_START_CMD:
console.print("Retrying:")
attempt = 0
while result.returncode != 0 and attempt < 10:
attempt += 1
time.sleep(1)
result = subprocess.run(
shlex.split(cmd), text=True, capture_output=True
)
if result.stderr and "ConnectionError" not in result.stderr:
break
if result.returncode == 0:
continue

console.print(f"Error while executing `{cmd}`")
raise typer.Exit(1)

Expand Down
Loading