在 Windows 上,URL-test/speed-test 失败,出现 connectex (WSAEADDRNOTAVAIL) 错误 – auto_detect_interface 在 BuildTestConfig() 中被无条件设置
作者: RynelHub创建于 2026年9月23日更新于 2026年9月23日
标签Need more InfoNot Reproducible
根本原因
在 src/configs/generate.cpp 中,持久(正常)路由配置仅在 TUN 模式打开时才启用 auto_detect_interface:
// 行 ~2126
if (settings.spmode_vpn && !route.contains("auto_detect_interface")) route["auto_detect_interface"] = true;
但是 `BuildTestConfig()`(用于 URL 测试/速度测试)则无条件地将其设置为 true,无论 TUN 状态如何:
```cpp
// 行 ~2662
QJsonObject routeObj{
{"auto_detect_interface", true},
{"default_domain_resolver", QJsonObject{
{"server", tags::dnsDirect},
{"strategy", getDirectDomainStrategy()},
}}
};
在 TUN 关闭时,持久实例永远不会设置此标志,并且正常连接。短暂的测试实例总是将其设置为 true,并且在本系统(以及其他系统上)中,sing-box 的 Windows `auto_detect_interface` 将出站套接字绑定到检测到的“默认接口”地址,该地址在 `connect()` 运行时可能已经过时 - 与观察到的“network: updated default interface”日志行在测试时触发的方式相匹配,并且与确切的 WSAEADDRNOTAVAIL 失败模式相匹配。内容来源: throneproj/Throne