mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-07-16 14:32:34 +00:00
perf(model-metadata): resolve localhost to IPv4 in detect_local_server_type
On Windows, `localhost` resolves to both ::1 (IPv6) and 127.0.0.1 (IPv4). httpx tries IPv6 first, hanging 2 sec per probe when the server binds IPv4 only. detect_local_server_type() is called 3+ times during init, each with a new httpx.Client, compounding to ~14s of dead time. Replace localhost with 127.0.0.1 inside the function before connecting. The function is only called for local endpoints (callers guard with is_local_endpoint()), so IPv6 loopback adds no diagnostic value. Measured: 19.9s → 4.0s on Windows with a local proxy on 127.0.0.1:8317.
This commit is contained in:
parent
05cbddc012
commit
a075d3194b
2 changed files with 66 additions and 0 deletions
|
|
@ -636,6 +636,12 @@ def detect_local_server_type(base_url: str, api_key: str = "") -> Optional[str]:
|
|||
server_url = server_url[:-3]
|
||||
lmstudio_url = _lmstudio_server_root(base_url)
|
||||
|
||||
# Resolve localhost to IPv4 to avoid 2s IPv6 timeout on Windows dual-stack.
|
||||
server_url = server_url.replace("://localhost:", "://127.0.0.1:")
|
||||
server_url = server_url.replace("://localhost/", "://127.0.0.1/")
|
||||
if server_url.endswith("://localhost"):
|
||||
server_url = server_url[:-len("localhost")] + "127.0.0.1"
|
||||
|
||||
headers = _auth_headers(api_key)
|
||||
|
||||
try:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue