SagerNet / sing-box

The universal proxy platform
https://sing-box.sagernet.org/
Other
19.54k stars 2.33k forks source link

长时间空置的 UDP 连接没有被关闭 #1297

Closed zacred0rryn closed 10 months ago

zacred0rryn commented 10 months ago

操作系统

Android

系统版本

12 (HarmonyOS 4.0.0.118)

安装类型

sing-box for Android 图形客户端程序

如果您使用图形客户端程序,请提供该程序版本。

1.8.0-rc.6

版本

/

描述

某些应用发起 UDP 连接以后,在一直没有传输数据的情况下,长时间 (可达数十小时) 闲置后这些连接不会被关闭。如下所示。

_截取该图时未仔细调整画面,我确认该截图中均为“手机 QQ”发起的 UDP 连接。_ ![图示](https://github.com/SagerNet/sing-box/assets/34595052/71047b51-cb41-4950-b516-5042081e0825)

重现方式

具体步骤:

  1. 清空 SFA 工作目录;使用所附配置文件,启动 SFA 服务。
  2. 开启一个会发起 UDP 连接的应用 (这里以“美团”应用 com.sankuai.meituan 为例);在应用中随便操作几下以后,关闭其后台,检查系统的应用管理,确认该应用已经完全关闭 (强行停止 功能为灰色不可交互状态)。
  3. 放置 (这里进行了 10 分钟)。在 yacd 面板中观察现象,发现该应用发起的 UDP 连接一直没有被关闭。

使用的配置文件如下。

```json { "log": { "level": "trace", "output": "/storage/emulated/0/Android/data/io.nekohasekai.sfa/files/sing-box.log", "timestamp": true }, "dns": { "servers": [ { "tag": "dns_remote", "address": "https://1.0.0.1/dns-query", "strategy": "prefer_ipv6" }, { "tag": "dns_local", "address": "h3://223.6.6.6/dns-query", "strategy": "prefer_ipv6", "detour": "direct" }, { "tag": "dns_fake", "address": "fakeip" }, { "tag": "dns_block", "address": "rcode://success" } ], "rules": [ { "outbound": "any", "server": "dns_local" }, { "query_type": "NIMLOC", "server": "dns_block", "disable_cache": true }, { "rule_set": [ "geosite-category-ads-all", "geosite-category-httpdns" ], "server": "dns_block", "disable_cache": true }, { "type": "logical", "mode": "and", "rules": [ { "rule_set": "geosite-geolocation-!cn", "invert": true }, { "rule_set": [ "geosite-cn", "geosite-category-companies@cn" ] } ], "server": "dns_local" }, { "query_type": [ "A", "AAAA" ], "server": "dns_fake", "disable_cache": true, "rewrite_ttl": 1 } ], "fakeip": { "enabled": true, "inet4_range": "198.18.0.0/15", "inet6_range": "fc00::/18" }, "strategy": "prefer_ipv4", "independent_cache": true }, "ntp": { "enabled": true, "server": "time.apple.com", "server_port": 123, "interval": "30m0s", "detour": "direct" }, "inbounds": [ { "type": "tun", "tag": "tun-in", "interface_name": "sing-tun", "mtu": 9000, "inet4_address": "172.19.0.1/30", "auto_route": true, "strict_route": true, "exclude_package": [ "com.nutomic.syncthingandroid", "com.limelight" ], "udp_timeout": 60000000000, "stack": "mixed", "platform": { "http_proxy": { "enabled": true, "server": "127.0.0.1", "server_port": 4070 } }, "sniff": true }, { "type": "mixed", "tag": "mixed-in", "listen": "127.0.0.1", "listen_port": 4070, "sniff": true, "domain_strategy": "prefer_ipv4" } ], "outbounds": [ { "type": "selector", "tag": "proxy", "outbounds": [ "auto", "manual" ] }, { "type": "selector", "tag": "manual", "outbounds": [ "节点 1 HKG", "节点 2 SGP", "节点 3 JPN", "节点 4 USA" ] }, { "type": "urltest", "tag": "auto", "outbounds": [ "节点 1 HKG", "节点 2 SGP", "节点 3 JPN", "节点 4 USA" ], "url": "http://www.gstatic.com/generate_204", "interval": "30m0s", "tolerance": 600 }, { "type": "direct", "tag": "direct" }, { "type": "block", "tag": "block" }, { "type": "dns", "tag": "dns-out" }, { "type": "shadowsocks", "tag": "节点 1 HKG", "server": "aexgzbgp01.004837963.xyz", "server_port": 14091, "method": "chacha20-ietf-poly1305", "password": "lE9uL5fR3yR9", "plugin": "obfs-local", "plugin_opts": "obfs=http;obfs-host=4362681c8a.iqiyi.com;" }, { "type": "shadowsocks", "tag": "节点 2 SGP", "server": "aexgzbgp01.004837963.xyz", "server_port": 14092, "method": "chacha20-ietf-poly1305", "password": "lE9uL5fR3yR9", "plugin": "obfs-local", "plugin_opts": "obfs=http;obfs-host=4362681c8a.iqiyi.com;" }, { "type": "shadowsocks", "tag": "节点 3 JPN", "server": "aexshbgp01.004837963.xyz", "server_port": 14093, "method": "chacha20-ietf-poly1305", "password": "lE9uL5fR3yR9", "plugin": "obfs-local", "plugin_opts": "obfs=http;obfs-host=4362681c8a.iqiyi.com;" }, { "type": "shadowsocks", "tag": "节点 4 USA", "server": "aexshbgp01.004837963.xyz", "server_port": 14094, "method": "chacha20-ietf-poly1305", "password": "lE9uL5fR3yR9", "plugin": "obfs-local", "plugin_opts": "obfs=http;obfs-host=4362681c8a.iqiyi.com;" } ], "route": { "rules": [ { "type": "logical", "mode": "or", "rules": [ { "port": 53 }, { "protocol": "dns" } ], "outbound": "dns-out" }, { "type": "logical", "mode": "or", "rules": [ { "port": 853 }, { "network": "udp", "port": 443 }, { "rule_set": "geoip-httpdns-cidr" } ], "outbound": "block" }, { "ip_is_private": true, "outbound": "direct" }, { "clash_mode": "Direct", "outbound": "direct" }, { "clash_mode": "Global", "outbound": "proxy" }, { "type": "logical", "mode": "and", "rules": [ { "rule_set": "geosite-geolocation-!cn", "invert": true }, { "rule_set": [ "geoip-cn", "geosite-cn", "geosite-category-companies@cn" ] } ], "outbound": "direct" } ], "rule_set": [ { "type": "remote", "tag": "geoip-cn", "format": "binary", "url": "https://testingcf.jsdelivr.net/gh/zacred0rryn/sing-geoip@rule-set/geoip-cn.srs", "download_detour": "direct", "update_interval": "72h0m0s" }, { "type": "remote", "tag": "geoip-httpdns-cidr", "format": "binary", "url": "https://testingcf.jsdelivr.net/gh/zacred0rryn/sing-geoip@rule-set/geoip-httpdns-cidr.srs", "download_detour": "direct", "update_interval": "168h0m0s" }, { "type": "remote", "tag": "geosite-category-ads-all", "format": "binary", "url": "https://testingcf.jsdelivr.net/gh/MetaCubeX/meta-rules-dat@sing/geo/geosite/category-ads-all.srs", "download_detour": "direct", "update_interval": "72h0m0s" }, { "type": "remote", "tag": "geosite-category-companies@cn", "format": "binary", "url": "https://testingcf.jsdelivr.net/gh/SagerNet/sing-geosite@rule-set/geosite-category-companies@cn.srs", "download_detour": "direct", "update_interval": "72h0m0s" }, { "type": "remote", "tag": "geosite-category-httpdns", "format": "binary", "url": "https://testingcf.jsdelivr.net/gh/zacred0rryn/sing-geosite@rule-set/geosite-category-httpdns.srs", "download_detour": "direct", "update_interval": "168h0m0s" }, { "type": "remote", "tag": "geosite-cn", "format": "binary", "url": "https://testingcf.jsdelivr.net/gh/SagerNet/sing-geosite@rule-set/geosite-cn.srs", "download_detour": "direct", "update_interval": "72h0m0s" }, { "type": "remote", "tag": "geosite-geolocation-!cn", "format": "binary", "url": "https://testingcf.jsdelivr.net/gh/SagerNet/sing-geosite@rule-set/geosite-geolocation-!cn.srs", "download_detour": "direct", "update_interval": "72h0m0s" } ], "auto_detect_interface": true }, "experimental": { "cache_file": { "enabled": true, "path": "./cache.db", "cache_id": "1" }, "clash_api": { "external_controller": "0.0.0.0:9090", "external_ui": "./ui", "external_ui_download_detour": "proxy", "default_mode": "Rule" } } } ```

我个人的复现结果如下图所示。

_该图内,`进程` 列中未显示包名,我确认图中的 UDP 连接是由 `com.sankuai.meituan` 发起的。_ ![复现结果](https://github.com/SagerNet/sing-box/assets/34595052/4c00b4b1-b1c8-4d57-a718-f64af1f176c5)

日志

未删减日志全文请见如下在线剪贴板链接。

全文较长,故分成两半提交: 第一部分 第二部分

完整性要求

负责性要求

nekohasekai commented 10 months ago

所有 TUN stack 均无法重现 NTP 请求完成后连接未关闭。

zacred0rryn commented 10 months ago

我尝试用我 PC 上的安卓模拟器用同样的过程复现了一次,结果是相同的…

![模拟器](https://github.com/SagerNet/sing-box/assets/34595052/d5e69ca5-c3cb-40ee-9d3e-9ada00e0003e)

这种表现应该是连接未关闭没错吧?

nekohasekai commented 10 months ago

你的问题非常模糊(平台特定,依赖 Android 模拟器与闭源软件),信息极少(只有连接没有关闭有用),使用简单配置无法复现。由于暂时没有人提供不用浪费开发者很多时间就能重现的方法,你可能需要自行学习怎么提供有效的信息。

zacred0rryn commented 10 months ago

了解了,不好意思。谢谢你。

由于我没有进一步研究此问题的具体形成条件及原因的能力、时间与精力,且此问题并不会对我造成过多困扰,所以我将关闭此 issue.