Panic: nil pointer dereference in WebsocketConn.Close during URL test
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 38.1k
- Forks
- 4.6k
- Avg merge
- 19d 15h
- Merged PRs (30d)
- 1
Description
Description
After updating to the latest version, sing-box crashes with a nil pointer dereference panic during URL testing.
Crash Report
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x75b8a91d08]
goroutine 217 [running]:
github.com/sagernet/sing-box/transport/v2raywebsocket.(*WebsocketConn).Close(0x0)
github.com/sagernet/sing-box/transport/v2raywebsocket/conn.go:49 +0x38
github.com/sagernet/sing/common.Close({0x757213fc90?, 0x1, 0x7572033710?})
github.com/sagernet/sing@v0.9.0-beta.4/common/cond.go:361 +0x178
github.com/sagernet/sing-box/protocol/trojan.(*trojanDialer).DialContext(0x7571dd1200, {0x75ba19ebf8?, 0x75728b83f0?}, {0x75b5e9ca20, 0x3}, {{{0x0, 0x0}, {0x0}}, 0x1bb, {0x7571ee3c58, ...}})
github.com/sagernet/sing-box/protocol/trojan/outbound.go:145 +0x408
github.com/sagernet/sing-box/protocol/trojan.(*Outbound).DialContext(0x7571dd1200, {0x75ba19ebf8, 0x75728b83f0}, {0x75b5e9ca20, 0x3}, {{{0x0, 0x0}, {0x0}}, 0x1bb, {0x7571ee3c58, ...}})
github.com/sagernet/sing-box/protocol/trojan/outbound.go:90 +0x33c
github.com/sagernet/sing-box/common/urltest.urlTest({0x75ba19ebf8, 0x75728b83f0}, {0x7571ee3c50?, 0x6e6d6c6967666563?}, {0x7987f12458, 0x7571dd1200})
github.com/sagernet/sing-box/common/urltest/urltest.go:112 +0x190
github.com/sagernet/sing-box/common/urltest.URLTest({0x75ba19ebf8, 0x75728b83f0}, {0x7571ee3c50, 0x24}, {0x7987f12458, 0x7571dd1200})
github.com/sagernet/sing-box/common/urltest/urltest.go:89 +0xa8
github.com/sagernet/sing-box/protocol/group.(*URLTestGroup).urlTest.func1.1()
github.com/sagernet/sing-box/protocol/group/urltest.go:406 +0x54
Root Cause
The WebSocket connection object is nil when Close() is called during the URL health check. The code attempts to close a nil connection without a nil check.
Expected Behavior
The code should check if the connection is nil before attempting to close it, or ensure the connection is properly initialized before use.
Environment
- Platform: Android ARM64
- sing-box version: Latest (after update)
- Protocol: Trojan with WebSocket transport
Suggested Fix
Add a nil check in v2raywebsocket/conn.go:49:
func (c *WebsocketConn) Close() error {
if c == nil {
return nil
}
// existing close logic
}
Or ensure the connection is properly initialized in the trojan dialer before use.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in transport/v2raywebsocket/conn.go at the Close method on line 49, then trace the URL-test path through common/urltest/urltest.go and protocol/trojan/outbound.go. Reproduce the Trojan WebSocket URL test if possible and verify that closing a nil connection no longer panics while normal connections still close correctly.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- networking
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 78/100