From 7cf7d2f7849936e3c84ee431433c2e8bcb6706ac Mon Sep 17 00:00:00 2001 From: historia Date: Wed, 26 Aug 2026 00:21:28 -0400 Subject: fix: harden server start/stop guards --- app/backends/probe.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'app/backends/probe.py') diff --git a/app/backends/probe.py b/app/backends/probe.py index efa2963..ada143a 100644 --- a/app/backends/probe.py +++ b/app/backends/probe.py @@ -108,11 +108,20 @@ def _identify_gradio(base: str, timeout: float) -> Optional[str]: return None +def _canonical_host(host: str) -> str: + """Fold the loopback aliases so "localhost" and "127.0.0.1" compare equal.""" + return "127.0.0.1" if host in ("localhost", "::1", "[::1]") else host + + def same_endpoint(url_a: str, url_b: str) -> bool: """True when URL_A and URL_B address the same host and port. Scheme and path are ignored (127.0.0.1:8080 and http://127.0.0.1:8080/ - are the same server). Returns False when either URL is empty/unparsable. + are the same server), and the loopback names are folded together + ("localhost:8080" equals "127.0.0.1:8080") — the config's remote-URL + defaults point at the managed servers, so a user writing either form + must not get their own server double-counted as "[remote]". + Returns False when either URL is empty/unparsable. """ if not url_a or not url_b: return False @@ -121,8 +130,8 @@ def same_endpoint(url_a: str, url_b: str) -> bool: b = urllib.parse.urlsplit(url_b) except ValueError: return False - host_a = a.hostname or "127.0.0.1" - host_b = b.hostname or "127.0.0.1" + host_a = _canonical_host(a.hostname or "127.0.0.1") + host_b = _canonical_host(b.hostname or "127.0.0.1") port_a = a.port or (443 if (a.scheme or "http") == "https" else 80) port_b = b.port or (443 if (b.scheme or "http") == "https" else 80) return host_a == host_b and port_a == port_b -- cgit v1.2.3