aboutsummaryrefslogtreecommitdiff
path: root/app/backends/probe.py
diff options
context:
space:
mode:
authorhistoria <historiavg@proton.me>2026-08-26 00:21:28 -0400
committerhistoria <historiavg@proton.me>2026-08-26 00:21:28 -0400
commit7cf7d2f7849936e3c84ee431433c2e8bcb6706ac (patch)
tree80d753cbd35929187ffc717a45f7bc3e9cbdbb1e /app/backends/probe.py
parent4c3e78c39c81d2997e88b84e1b5a25b244e870e4 (diff)
downloadtts-audiobook-generator-7cf7d2f7849936e3c84ee431433c2e8bcb6706ac.tar.gz
fix: harden server start/stop guards
Diffstat (limited to 'app/backends/probe.py')
-rw-r--r--app/backends/probe.py15
1 files changed, 12 insertions, 3 deletions
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