sing-box crashed when incoming connection is vmess+grpc
Welcome
- [X] Yes, I'm using the latest major release. Only such installations are supported.
- [X] Yes, I'm using the latest Golang release. Only such installations are supported.
- [X] Yes, I've searched similar issues on GitHub and didn't find any.
- [X] Yes, I've included all information below (version, FULL config, FULL log, etc).
Description of the problem
sing-box 服务器配置了一个 vmess 服务,底层传输协议为 gRPC。当客户端发起一个请求(具体来说,是在 v2rayN 里点击“测试服务器真连接延迟”时),sing-box 服务端将会 panic 虽然我知道可能会被认为是 v2rayN 客户端的问题,但是“测试服务器真连接延迟”功能只是对 google.com 发起了一个请求并立即关闭连接而已,理应考虑是 sing-box 存在问题
Version of sing-box
$ ./sing-box version
sing-box version 1.1.2
Environment: go1.19.4 linux/amd64
Tags: with_gvisor,with_quic,with_wireguard,with_utls,with_clash_api
Revision: ff0693be3210e6434eb1d6be7eb21c5bc1ffde88
CGO: disabled
Server and client configuration file
{
"inbounds": [
{
"type": "vmess",
"tag": "vmess-in",
"listen": "::",
"listen_port": 8838,
"users": [
{
"uuid": "<Redacted>",
"alterId": 0
}
],
"tls": {
"enabled": true,
"certificate_path": "/etc/sing-box/server.crt",
"key_path": "/etc/sing-box/server.key"
},
"transport": {
"type": "grpc",
"service_name": "<Redacted>"
}
}
]
}
Server and client log file
DEBUG[0005] [531608215] inbound/vmess[vmess-in]: connection closed: process connection from x.x.x.x:<port>: mux connection closed: read frame header: use of closed network connection
panic: Write called after Handler finished
goroutine 43 [running]:
golang.org/x/net/http2.(*responseWriter).write(0x0?, 0x45d959?, {0xc000248009?, 0xd92ca8?, 0x17a29a0?}, {0x0?, 0xc0002fba60?})
pkg/mod/golang.org/x/[email protected]/http2/server.go:2927 +0x150
golang.org/x/net/http2.(*responseWriter).Write(0xc000248028?, {0xc000248009?, 0x7fd8?, 0xdf2180?})
pkg/mod/golang.org/x/[email protected]/http2/server.go:2916 +0x30
github.com/sagernet/sing/common/rw.WriteBytes(...)
pkg/mod/github.com/sagernet/[email protected]/common/rw/write.go:16
github.com/sagernet/sing-box/transport/v2raygrpclite.(*GunConn).WriteBuffer(0xc000146820, 0xc0000a1050)
/home/sekai/Projects/sing-box/transport/v2raygrpclite/conn.go:123 +0x182
github.com/sagernet/sing-vmess.(*StreamChunkWriter).WriteBuffer(0xc000122ac0, 0xc0000a1050)
pkg/mod/github.com/sagernet/[email protected]/chunk_length_stream.go:161 +0x2c7
github.com/sagernet/sing-vmess.(*AEADWriter).WriteBuffer(0xc000122b00, 0xc0000a1050)
pkg/mod/github.com/sagernet/[email protected]/chunk_aead.go:120 +0x107github.com/sagernet/sing/common/bufio.WriteBuffer({0x1157778?, 0xc000122b00}, 0xc0000a1020)
pkg/mod/github.com/sagernet/[email protected]/common/bufio/io.go:51 +0x1e2
github.com/sagernet/sing-vmess.(*AEADWriter).Write(0x7f9834659108?, {0xc0000f0000, 0x6, 0x1000})
pkg/mod/github.com/sagernet/[email protected]/chunk_aead.go:99 +0x85
github.com/sagernet/sing/common/bufio.(*ChunkWriter).Write(0xc00011a690, {0xc0000f0000?, 0x8?, 0xc0002fbd30?})
pkg/mod/github.com/sagernet/[email protected]/common/bufio/chunk.go:85 +0xe9github.com/sagernet/sing-vmess.(*serverConn).Write(0x114f280?, {0xc0000f0000?, 0x1165820?, 0x184bc30?})
pkg/mod/github.com/sagernet/[email protected]/service.go:444 +0x67
bufio.(*Writer).Flush(0xc0001228c0)
$GOROOT/src/bufio/bufio.go:629 +0x62
github.com/sagernet/sing-vmess.(*serverSession).syncClose(0xc00017e680, 0x1?, 0x30?)
pkg/mod/github.com/sagernet/[email protected]/mux.go:359 +0xd3
github.com/sagernet/sing-vmess.(*serverSession).close(0xe7ee80?, 0x5720?, {0x0, 0x0?})
pkg/mod/github.com/sagernet/[email protected]/mux.go:333 +0x4b
github.com/sagernet/sing-vmess.(*serverMuxConn).Close(0xc00004a140?)
pkg/mod/github.com/sagernet/[email protected]/mux.go:424 +0x27
github.com/sagernet/sing/common.Close({0xc0002fbe80?, 0x1, 0xe7ef00?})
pkg/mod/github.com/sagernet/[email protected]/common/cond.go:324 +0xa4
github.com/sagernet/sing/common/bufio.CopyConn.func4({0x0?, 0x0?})
pkg/mod/github.com/sagernet/[email protected]/common/bufio/copy.go:218 +0xe2github.com/sagernet/sing/common/task.(*Group).Run.func1()
pkg/mod/github.com/sagernet/[email protected]/common/task/task.go:59 +0x93
created by github.com/sagernet/sing/common/task.(*Group).Run
pkg/mod/github.com/sagernet/[email protected]/common/task/task.go:58 +0x54a
Try 801c18b612228310e9cc0bc4c89f06bdd2c45a19
崩了
客户端和服务端都是https://github.com/SagerNet/sing-box/commit/801c18b612228310e9cc0bc4c89f06bdd2c45a19
panic: buffer overflow: cap 32768,start 0, need 7
goroutine 75 [running]:
github.com/sagernet/sing/common/buf.(*Buffer).ExtendHeader(0xc00036dd88, 0x7)
github.com/sagernet/[email protected]/common/buf/buffer.go:150 +0x1b9
github.com/sagernet/sing-box/transport/v2raygrpclite.(*GunConn).WriteBuffer(0xc0001b5130, 0xc00036dd88)
github.com/sagernet/sing-box/transport/v2raygrpclite/conn.go:119 +0x9f
github.com/sagernet/sing/common/bufio.(*ExtendedConnWrapper).WriteBuffer(0x7fae7a4a9108?, 0x30?)
github.com/sagernet/[email protected]/common/bufio/conn.go:219 +0x22
github.com/sagernet/sing-box/transport/v2rayhttp.(*HTTP2ConnWrapper).WriteBuffer(0xfcbea0?, 0xc000155b00?)
github.com/sagernet/sing-box/transport/v2rayhttp/conn.go:140 +0xe3
github.com/sagernet/sing/common/bufio.CopyExtendedBuffer({0x7fae52fc5970?, 0xc00033e120}, {0x11f60a8, 0xc00016f5a0}, 0xc00036dd88)
github.com/sagernet/[email protected]/common/bufio/copy.go:121 +0x206
github.com/sagernet/sing/common/bufio.CopyExtended({0x7fae52fc5970?, 0xc00033e120}, {0x11f60a8?, 0xc00016f5a0})
github.com/sagernet/[email protected]/common/bufio/copy.go:99 +0x2d4
github.com/sagernet/sing/common/bufio.Copy({0x7fae52fc5910, 0xc00033e120}, {0x11f0060?, 0xc0000122c0?})
github.com/sagernet/[email protected]/common/bufio/copy.go:75 +0x394
github.com/sagernet/sing/common/bufio.CopyConn.func4({0x0?, 0x0?})
github.com/sagernet/[email protected]/common/bufio/copy.go:218 +0xc9
github.com/sagernet/sing/common/task.(*Group).Run.func1()
github.com/sagernet/[email protected]/common/task/task.go:59 +0x93
created by github.com/sagernet/sing/common/task.(*Group).Run
github.com/sagernet/[email protected]/common/task/task.go:58 +0x54a
Try 4afde2e7cf48fb28e148186a0568601ed62bd6ae
https://github.com/SagerNet/sing-box/commit/4afde2e7cf48fb28e148186a0568601ed62bd6ae Fixed.
This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 5 days