SagerNet / sing-box

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

vmess network:tcp 报错 #1416

Closed cyouhi closed 5 months ago

cyouhi commented 5 months ago

操作系统

Windows

系统版本

win10 x64

安装类型

sing-box 原始命令行程序

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

No response

版本

1.8.4

描述

在vmess协议中启用network:tcp后,使用sing-box.exe check时报错

重现方式

{ "log": { "disabled": false, "level": "info", "output": "box.log", "timestamp": true }, "dns": { "servers": [ { "tag": "remote", "address": "https://dns.cloudflare.com/dns-query", "address": "tls://dns.google", "address_resolver": "local", "detour": "vmess" }, { "tag": "google", "address": "tls://dns.google", "address_resolver": "local", "detour": "vmess" }, { "tag": "local", "address": "10.172.0.247", "strategy": "prefer_ipv6", "detour": "direct" }, { "tag": "block", "address": "rcode://success" } ], "rules": [ { "domain": [ "mapi.pcdn.club" ], "server": "local" }, { "domain_suffix": [ "apkpure.com" ], "server": "remote" }, { "rule_set": "geosite-category-ads-all", "server": "block" }, { "rule_set": [ "geosite-cn", "geosite-apple", "geosite-microsoft" ], "server": "local" }, { "rule_set": [ "geosite-github" ], "server": "remote" }, { "outbound": "any", "server": "remote" } ] }, "ntp": { "enabled": true, "server": "time.apple.com", "server_port": 123, "interval": "30m0s", "detour": "direct" }, "inbounds": [ { "type": "tun", "tag": "tun-in", "interface_name": "sing-box", "inet4_address": "172.19.0.1/30", "inet6_address": "fdfe:dcba:9876::1/126", "mtu": 9000, "auto_route": true, "strict_route": true, "udp_timeout": "5m0s", "stack": "mixed", "sniff": true, "sniff_timeout": "300ms", "domain_strategy": "prefer_ipv6" }, { "type": "mixed", "tag": "mixed-in", "listen": "::", "listen_port": 10808, "tcp_fast_open": true, "tcp_multi_path": true, "udp_fragment": false, "udp_timeout": "5m", "sniff": true, "sniff_override_destination": true, "sniff_timeout": "300ms", "domain_strategy": "prefer_ipv6", "udp_disable_domain_unmapping": false }, { "type": "shadowsocks", "listen": "::", "listen_port": 2087, "sniff": true, //"network": "tcp", "method": "2022-blake3-aes-128-gcm", "password": "JWnZrCVkTLlLrrd5YkMGaQ==" } ], "outbounds": [ { "type": "vmess", "tag": "vmess", "server": "ipv6地址", "server_port": 8443, "uuid": "7fe", "security": "auto", "alter_id": 0, "global_padding": false, "authenticated_length": true, "network": "tcp", "tls": { "enabled": true, "disable_sni": false, "server_name": "", "utls": { "enabled": true, "fingerprint": "chrome" } }, "packet_encoding": "packetaddr", "transport": { "type": "ws", "path": "/b1bffe", "headers": { "host": "" } } }, { "type": "vmess", "tag": "vmess2", "server": "ipv4", "server_port": 8443, "uuid": "57", "security": "auto", "alter_id": 0, "global_padding": false, "authenticated_length": true, "network": "tcp", "tls": { "enabled": true, "disable_sni": false, "server_name": "ok", "utls": { "enabled": true, "fingerprint": "chrome" } }, "packet_encoding": "packetaddr", "transport": { "type": "ws", "path": "/5", "headers": { "host": "" } } }, { "type": "direct", "tag": "direct" }, { "type": "block", "tag": "block" }, { "type": "dns", "tag": "dns-out" } ], "route": { "rules": [ { "protocol": "dns", "outbound": "dns-out" }, { "ip_is_private": true, "outbound": "direct" }, { //tg分流 "ip_cidr": [ "91.108.4.0/22", "91.108.8.0/22", "91.108.12.0/22", "91.108.16.0/22", "91.108.56.0/22", "109.239.140.0/24", "149.154.160.0/22", "149.154.164.0/22", "149.154.168.0/22", "149.154.172.0/22" ], "outbound": "vmess2" }, { //tg分流 "ip_cidr": [ "2001:b28:f23f::/48", "2001:67c:4e8::/48", "2001:b28:f23d::/48", "2a0a:f280::/29" ], "outbound": "vmess" }, { "rule_set": "geosite-category-ads-all", "outbound": "block" }, { "rule_set": [ "geosite-github" ], "outbound": "vmess" }, { "rule_set": [ "geoip-cn", "geosite-cn", "geosite-apple", "geosite-microsoft" ], "outbound": "direct" } ], "rule_set": [ { "type": "remote", "tag": "geoip-cn", "format": "binary", "url": "https://raw.githubusercontent.com/SagerNet/sing-geoip/rule-set/geoip-cn.srs", "download_detour": "vmess" }, { "type": "remote", "tag": "geosite-cn", "format": "binary", "url": "https://raw.githubusercontent.com/SagerNet/sing-geosite/rule-set/geosite-cn.srs", "download_detour": "vmess" }, { "type": "remote", "tag": "geosite-category-ads-all", "format": "binary", "url": "https://raw.githubusercontent.com/SagerNet/sing-geosite/rule-set/geosite-category-ads-all.srs", "download_detour": "vmess" }, { "type": "remote", "tag": "geosite-apple", "format": "binary", "url": "https://raw.githubusercontent.com/SagerNet/sing-geosite/rule-set/geosite-apple.srs", "download_detour": "vmess" }, { "type": "remote", "tag": "geosite-github", "format": "binary", "url": "https://raw.githubusercontent.com/SagerNet/sing-geosite/rule-set/geosite-github.srs", "download_detour": "vmess" }, { "type": "remote", "tag": "geosite-microsoft", "format": "binary", "url": "https://raw.githubusercontent.com/SagerNet/sing-geosite/rule-set/geosite-microsoft.srs", "download_detour": "vmess" } ], "auto_detect_interface": true, "final": "vmess" }, "experimental": { "cache_file": { "enabled": true } } }

日志

panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xc0000005 code=0x0 addr=0x18 pc=0x12e319e]

goroutine 1 [running]:
github.com/sagernet/sing-box/log.(*observableLogger).Log(0xc000226648, {0x20c7b00, 0x2b33540}, 0x25?, {0xc000246410, 0x5, 0x5})
        /Users/sekai/Projects/sing-box/log/observable.go:131 +0x45e
github.com/sagernet/sing-box/log.(*observableLogger).InfoContext(...)
        /Users/sekai/Projects/sing-box/log/observable.go:178
github.com/sagernet/sing-box/log.(*observableLogger).Info(0xc0001c5d10?, {0xc000246410?, 0xc000220dc0?, 0xb?})
        /Users/sekai/Projects/sing-box/log/observable.go:150 +0x35
github.com/sagernet/sing-box/route.(*Router).Initialize(0xc00013cb00, {0xc0002481b0, 0x3, 0x7?}, {0xc0002463c0, 0x5, 0x5}, 0xc00023bc20)
        /Users/sekai/Projects/sing-box/route/router.go:401 +0xb58
github.com/sagernet/sing-box.New({{{0xc00018e000, 0x1c95, 0x1e00}, {0x0, 0x0}, 0xc00019acc0, 0xc0001687e0, 0xc0000f44d0, {0xc0001d0000, 0x3, ...}, ...}, ...})
        /Users/sekai/Projects/sing-box/box.go:141 +0x114a
main.check()
        /Users/sekai/Projects/sing-box/cmd/sing-box/cmd_check.go:34 +0x138
main.glob..func1(0xc000131900?, {0xc0000ad320?, 0x4?, 0x1ec9993?})
        /Users/sekai/Projects/sing-box/cmd/sing-box/cmd_check.go:16 +0x17
github.com/spf13/cobra.(*Command).execute(0x2ad0c80, {0xc0000ad300, 0x2, 0x2})
        pkg/mod/github.com/spf13/cobra@v1.8.0/command.go:987 +0xaa3
github.com/spf13/cobra.(*Command).ExecuteC(0x2ad20a0)
        pkg/mod/github.com/spf13/cobra@v1.8.0/command.go:1115 +0x3ff
github.com/spf13/cobra.(*Command).Execute(...)
        pkg/mod/github.com/spf13/cobra@v1.8.0/command.go:1039
main.main()
        /Users/sekai/Projects/sing-box/cmd/sing-box/main.go:38 +0x1e

完整性要求

poetlife commented 5 months ago

移除log中的"output": "box.log"就不会报错,追着看下去,似乎就是 https://github.com/SagerNet/sing-box/commit/21283b554a4d7e399cbf6fc8d4f7efca9e9f8442 中针对log/log.go的修改导致了后续日志如果是有output就会报错了。

poetlife commented 5 months ago

又研究了以下,这个实际上只会在check的时候出现,在run的时候,实际上会通过err = instance.Start()启动日志相关的服务。

cyouhi commented 5 months ago

实际运行时如果有output:log的话也会报check那样的错误

在 2024年2月1日星期四,Pykt @.***> 写道:

又研究了以下,这个实际上只会在check的时候出现,在run的时候,实际上会通过err = instance.Start()启动日志相关的服务。

— Reply to this email directly, view it on GitHub https://github.com/SagerNet/sing-box/issues/1416#issuecomment-1919514078, or unsubscribe https://github.com/notifications/unsubscribe-auth/AH5YMFXNGEI3WJEWXXDAECTYRJZMLAVCNFSM6AAAAABCOXS57OVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSMJZGUYTIMBXHA . You are receiving this because you authored the thread.Message ID: @.***>

poetlife commented 5 months ago

这里就是有问题,看了下代码的启动逻辑,在box.goNew()方法里实际上就是先初始化了router、imbounds、outbounds,且在初始化过程中有可能打印日志的,但是如果使用了日志文件的话,那就是在:

// box.go
func (s *Box) preStart() error {
err := s.logFactory.Start()
}

中才进行创建的,如果是这个设定,那么基本上打印日志到文件就废了。