mirror of
https://github.com/baoweise-bot/aimili-vpngate.git
synced 2026-09-08 17:26:46 +08:00
fix: optimize exit connection diagnostics by verifying local port accessibility before running obstruction checks and update global state variables
This commit is contained in:
+30
-1
@@ -4197,6 +4197,35 @@ def check_proxy_health() -> dict[str, Any]:
|
|||||||
if result:
|
if result:
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
# 此时外网测试失败,检测本地代理端口是否依然能连通。若仍能连通,直接抛出出口测试失败,不调用占用诊断
|
||||||
|
port_still_listening = False
|
||||||
|
test_sock = None
|
||||||
|
try:
|
||||||
|
test_sock = socket.socket(af, socket.SOCK_STREAM)
|
||||||
|
test_sock.settimeout(1.0)
|
||||||
|
connect_host = LOCAL_PROXY_HOST
|
||||||
|
if connect_host in ("::", "0.0.0.0", ""):
|
||||||
|
connect_host = "::1" if is_ipv6 else "127.0.0.1"
|
||||||
|
try:
|
||||||
|
test_sock.connect((connect_host, LOCAL_PROXY_PORT))
|
||||||
|
port_still_listening = True
|
||||||
|
except Exception:
|
||||||
|
if connect_host == "::1":
|
||||||
|
test_sock.close()
|
||||||
|
test_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
|
test_sock.settimeout(1.0)
|
||||||
|
test_sock.connect(("127.0.0.1", LOCAL_PROXY_PORT))
|
||||||
|
port_still_listening = True
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
finally:
|
||||||
|
if test_sock is not None:
|
||||||
|
try:
|
||||||
|
test_sock.close()
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
|
if not port_still_listening:
|
||||||
diag = vpn_utils.diagnose_local_obstructions(LOCAL_PROXY_PORT, host=LOCAL_PROXY_HOST)
|
diag = vpn_utils.diagnose_local_obstructions(LOCAL_PROXY_PORT, host=LOCAL_PROXY_HOST)
|
||||||
if diag:
|
if diag:
|
||||||
return {"ok": False, "error": f"出口连接测试失败 | 本机诊断结果: {diag[1]}"}
|
return {"ok": False, "error": f"出口连接测试失败 | 本机诊断结果: {diag[1]}"}
|
||||||
@@ -4206,7 +4235,7 @@ def check_proxy_health() -> dict[str, Any]:
|
|||||||
return {"ok": False, "error": f"出口连接测试异常: {e}"}
|
return {"ok": False, "error": f"出口连接测试异常: {e}"}
|
||||||
|
|
||||||
def background_proxy_checker() -> None:
|
def background_proxy_checker() -> None:
|
||||||
global last_checker_heartbeat
|
global last_checker_heartbeat, is_connecting
|
||||||
time.sleep(30)
|
time.sleep(30)
|
||||||
while True:
|
while True:
|
||||||
last_checker_heartbeat = time.time()
|
last_checker_heartbeat = time.time()
|
||||||
|
|||||||
Reference in New Issue
Block a user