Skip to content

Commit a2d6a05

Browse files
authored
iris: pin tunnel port scan to start at 10000 (#3679)
Makes the dashboard port stable across restarts so developers can bookmark or refresh the page copy-pasting the new port each time.
1 parent 3b03c97 commit a2d6a05

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

lib/iris/src/iris/cluster/platform/base.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,11 @@
3030

3131
import datetime
3232
import logging
33+
import os
3334
import socket
3435
import threading
3536
import uuid
37+
from pathlib import Path
3638
from collections.abc import Callable
3739
from contextlib import AbstractContextManager
3840
from dataclasses import dataclass, field
@@ -95,9 +97,17 @@ def find_free_port(start: int = -1) -> int:
9597
s.bind(("", 0))
9698
return s.getsockname()[1]
9799
for port in range(start, start + 1000):
100+
lock = Path(f"/tmp/iris/port_{port}")
101+
try:
102+
os.kill(int(lock.read_text()), 0)
103+
continue # port locked by a live process
104+
except (FileNotFoundError, ValueError, ProcessLookupError, PermissionError):
105+
pass
98106
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
99107
try:
100108
s.bind(("", port))
109+
lock.parent.mkdir(parents=True, exist_ok=True)
110+
lock.write_text(str(os.getpid()))
101111
return port
102112
except OSError:
103113
continue

lib/iris/src/iris/cluster/platform/coreweave.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1500,7 +1500,7 @@ def _coreweave_tunnel(
15001500
exits (e.g. konnectivity timeout), it is relaunched automatically.
15011501
"""
15021502
if local_port is None:
1503-
local_port = find_free_port()
1503+
local_port = find_free_port(start=10000)
15041504

15051505
proc: subprocess.Popen | None = None
15061506

lib/iris/src/iris/cluster/platform/gcp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1609,7 +1609,7 @@ def _gcp_tunnel(
16091609
Picks a free port automatically if none is specified.
16101610
"""
16111611
if local_port is None:
1612-
local_port = find_free_port()
1612+
local_port = find_free_port(start=10000)
16131613

16141614
labels = Labels(label_prefix)
16151615
label_filter = f"labels.{labels.iris_controller}=true AND status=RUNNING"

0 commit comments

Comments
 (0)