MetaCubeX / mihomo

A simple Python Pydantic model for Honkai: Star Rail parsed data from the Mihomo API.
https://wiki.metacubex.one
MIT License
16.58k stars 2.65k forks source link

[Bug] TUN 模式长时间使用出现 panic 崩溃 #1168

Closed TGSAN closed 7 months ago

TGSAN commented 7 months ago

Verify steps

Mihomo version

Mihomo Meta alpha-c44949b windows amd64 with go1.22.1 Sat Apr 6 21:30:53 UTC 2024 Use tags: with_gvisor

What OS are you seeing the problem on?

Windows

Mihomo config

mode: rule
mixed-port: 7897
socks-port: 7898
port: 7899
allow-lan: false
log-level: info
ipv6: true
secret: ''
external-controller: 127.0.0.1:9097
tcp-concurrent: true
global-client-fingerprint: chrome
keep-alive-interval: 3600
unified-delay: true
tun:
  enable: true
  stack: gvisor
  endpoint-independent-nat: true
  auto-detect-interface: true
  auto-route: true
  strict_route: true
  device: Clash Meta
  dns-hijack:
  - 198.18.0.2:53
  - tcp://198.18.0.2:53
  - '[fdfe:dcba:9876::2]:53'
  - tcp://[fdfe:dcba:9876::2]:53
  mtu: 9000
  strict-route: false
dns:
  enable: true
  ipv6: true
  use-hosts: true
  enhanced-mode: redir-host
  nameserver:
  - cleardns1.intranal
  - cleardns2.intranal
  fake-ip-filter:
  - +.*
  fake-ip-range: 198.18.0.1/16
  fallback: []
experimental:
  sniff-tls-sni: true
sniffer:
  enable: true
  override-destination: false
  sniff:
    QUIC:
      ports:
      - 443
      - 8443
    TLS:
      ports:
      - 443
      - 8443
    HTTP:
      ports:
      - 80
      - 8080-8880
  skip-domain:
  - Mijia Cloud
  - dlg.io.mi.com
  - +.apple.com
  - +.jd.com
  force-domain:
  - +
proxies:
- name: 日本 NTT (UDP, Trojan)
  type: trojan
  server: hideurl
  port: 443
  password: password
  network: ws
  sni: hideurl
  skip-cert-verify: false
  udp: true
  ws-opts:
    path: /ws
    headers:
      Host: hideurl
- name: Office
  type: ss
  server: 192.168.2.2
  port: 114
  cipher: rc4-md5
  password: '514'
  udp: true
- name: 日本 NTT (UDP, Fast, Hysteria2)
  type: hysteria2
  server: hideurl
  port: 443
  password: password
  sni: hideurl
  skip-cert-verify: false
proxy-groups:
- name: 大陆IP规则 (TCP)
  type: select
  disable-udp: true
  proxies:
  - DIRECT
  - Office
- name: 大陆IP规则 (UDP)
  type: select
  proxies:
  - DIRECT
  - Office
- name: 海外IP规则 (TCP)
  type: select
  disable-udp: true
  proxies:
  - "日本 NTT (UDP, Trojan)"
  - "日本 NTT (UDP, Fast, Hysteria2)"
  - DIRECT
- name: 海外IP规则 (UDP)
  type: select
  proxies:
  - "日本 NTT (UDP, Fast, Hysteria2)"
  - "日本 NTT (UDP, Trojan)"
  - DIRECT
rules:
- GEOIP,CN,大陆IP规则 (TCP)
- GEOIP,CN,大陆IP规则 (UDP)
- GEOIP,LAN,DIRECT
- MATCH,海外IP规则 (TCP)
- MATCH,海外IP规则 (UDP)

Mihomo log

time="2024-04-07T15:24:37.5746326+08:00" level=info msg="[TCP] 198.18.0.1:65499 --> 182.254.116.117:80 match GeoIP(cn) using 大陆IP规则 (TCP)[Office]"
time="2024-04-07T15:24:37.5746966+08:00" level=info msg="[TCP] 198.18.0.1:65498 --> 182.254.116.117:80 match GeoIP(cn) using 大陆IP规则 (TCP)[Office]"
time="2024-04-07T15:24:37.7140807+08:00" level=info msg="[TCP] 198.18.0.1:65519 --> 182.254.116.117:80 match GeoIP(cn) using 大陆IP规则 (TCP)[Office]"
time="2024-04-07T15:24:37.8659147+08:00" level=info msg="[TCP] 198.18.0.1:65531 --> 182.254.116.117:80 match GeoIP(cn) using 大陆IP规则 (TCP)[Office]"
time="2024-04-07T15:24:37.9343785+08:00" level=info msg="[TCP] 198.18.0.1:49152 --> 182.254.116.117:80 match GeoIP(cn) using 大陆IP规则 (TCP)[Office]"
time="2024-04-07T15:24:37.9355686+08:00" level=info msg="[TCP] 198.18.0.1:65534 --> 182.254.116.117:80 match GeoIP(cn) using 大陆IP规则 (TCP)[Office]"
time="2024-04-07T15:24:38.1188476+08:00" level=info msg="[TCP] 198.18.0.1:49156 --> 182.254.116.117:80 match GeoIP(cn) using 大陆IP规则 (TCP)[Office]"
time="2024-04-07T15:24:38.1194148+08:00" level=info msg="[TCP] 198.18.0.1:49155 --> 182.254.116.117:80 match GeoIP(cn) using 大陆IP规则 (TCP)[Office]"
time="2024-04-07T15:24:38.145375+08:00" level=info msg="[TCP] 198.18.0.1:49159 --> 182.254.116.117:80 match GeoIP(cn) using 大陆IP规则 (TCP)[Office]"
time="2024-04-07T15:24:38.2153399+08:00" level=info msg="[TCP] 198.18.0.1:65476 --> clientnotification-userprodea1-0.servicebus.windows.net:9354 match Match using 海外IP规则 (TCP)[Global Anycast Smart -> 日本 NTT (UDP, Trojan)]"
time="2024-04-07T15:24:38.2299851+08:00" level=info msg="[TCP] 198.18.0.1:65478 --> login.microsoftonline.com:443 match Match using 海外IP规则 (TCP)[Global Anycast Smart -> 日本 NTT (UDP, Trojan)]"
panic: runtime error: slice bounds out of range [:2102] with capacity 2048

goroutine 107726 [running]:
github.com/sagernet/sing/common/buf.(*Buffer).Bytes(...)
        github.com/sagernet/sing@v0.3.6/common/buf/buffer.go:339
github.com/metacubex/sing-tun.(*UDPBackWriter).WritePacket(0xc0024a5cb0, 0xc001433580, {{{0xfdfedcba98760000, 0x2}, 0xc0001180a8}, 0x35, {0x0, 0x0}})
        github.com/metacubex/sing-tun@v0.2.1-0.20240405021556-f37a4aa3d060/stack_gvisor_udp.go:113 +0xb5c
github.com/sagernet/sing/common/udpnat.(*conn).WritePacket(0xc001a7d580?, 0xc0006fae70?, {{{0xfdfedcba98760000, 0x2}, 0xc0001180a8}, 0x35, {0x0, 0x0}})
        github.com/sagernet/sing@v0.3.6/common/udpnat/service.go:134 +0x57
github.com/metacubex/mihomo/listener/sing_tun.(*ListenerHandler).NewPacketConnection.func3()
        github.com/metacubex/mihomo/listener/sing_tun/dns.go:116 +0x2c6
created by github.com/metacubex/mihomo/listener/sing_tun.(*ListenerHandler).NewPacketConnection in goroutine 105320
        github.com/metacubex/mihomo/listener/sing_tun/dns.go:91 +0x465

Description

使用 gvisor 栈的 tun 使用一段时间后内核会 panic 崩溃,出现频率一天三次左右。如果系统经常锁屏进入睡眠,然后唤醒会更容易出现 panic。
(配置文件出现的cleardns*.intranal是内网的无污染DNS服务器)

wwqgtxx commented 7 months ago

试试 https://github.com/MetaCubeX/mihomo/commit/bd703b8ff29754c7f0a87b4ff60160bf3314d226

TGSAN commented 7 months ago

试试 bd703b8

最新的Alpha版本开了一个晚上没有出现崩溃,看上去问题修复了,感谢作者!